From 89cc8f054c27f70fcfe16f14554a8a12e0c19e23 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期三, 18 十二月 2019 09:22:31 +0800 Subject: [PATCH] 邀请统计 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java | 101 +++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 90 insertions(+), 11 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java index 2722005..7351ed1 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java +++ b/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,11 @@ 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.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 +41,8 @@ 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.MQMsgBodyFactory; +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 @@ -306,7 +316,7 @@ FrequencyEnum frequency = integralTask.getFrequency(); if (frequency == FrequencyEnum.everyday) { int num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId, - TimeUtil.getWholeTime(record.getCreateTime().getTime())); + TimeUtil.getWholeTime(record.getCreateTime().getTime()), record.getId()); if (num <= 0) num = 1; String title = taskClass.getName() + "-" + integralTask.getName() + "-绗�" + num + "娆�"; @@ -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 = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.integralTaskFinish, + msg); + producer.send(message); + } + return record; } @@ -373,6 +392,11 @@ @Override public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) { return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count); + } + + @Override + public long getTotalGoldCoinByUid(Long uid) { + return integralTaskRecordMapper.getTotalGoldCoinByUid(uid); } @Async() @@ -446,16 +470,18 @@ if (userInfoExtra == null) return; - Integer goldCoin = userInfoExtra.getGoldCoin(); - if (goldCoin == null) - goldCoin = 0; - goldCoin = goldCoin + addGoldCoin; - + int totalGoldCoin = 0; try { UserInfoExtra extra = new UserInfoExtra(); extra.setId(userInfoExtra.getId()); - extra.setGoldCoin(goldCoin); + Integer goldCoin = userInfoExtra.getGoldCoin(); + if (goldCoin == null) { + extra.setGoldCoin(addGoldCoin); + } else { + extra.setGoldCoin(goldCoin + addGoldCoin); + } userInfoExtraService.saveUserInfoExtra(extra); + totalGoldCoin = extra.getGoldCoin(); } catch (UserInfoExtraException e) { LogHelper.errorDetailInfo(e); return; @@ -475,7 +501,7 @@ MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO(); msgOther.setTitle("閲戝竵濂栧姳"); msgOther.setNum(addGoldCoin + "閲戝竵"); - msgOther.setTotal(goldCoin + "閲戝竵"); + msgOther.setTotal(totalGoldCoin + "閲戝竵"); if (StringUtil.isNullOrEmpty(level)) { msgOther.setSource("棣栫瑪鍒嗕韩璁㈠崟锛岀郴缁熷鍔遍噾甯� "); msgOther.setExplain("棣栫瑪鍒嗕韩璁㈠崟寰楀埌鐨勫閲戜笉瓒�0.01鍏冩椂濂栧姳 "); @@ -485,4 +511,57 @@ } userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther); } + + /** + * 鎺ㄥ箍绾㈠寘鎶樼畻閲戝竵 + * + * @param uid + * @param addGoldCoin + * @param tlj + */ + @Override + @Transactional(rollbackFor = Exception.class) + 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); + } } -- Gitblit v1.8.0