From 7e7db2fa55a9a3af46d4fd8ede0dee147f101d64 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 09 五月 2020 21:41:27 +0800 Subject: [PATCH] 2.1需求 --- fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java | 102 ++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 80 insertions(+), 22 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java index ddb7293..45ab717 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java @@ -2,7 +2,9 @@ import java.math.BigDecimal; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import javax.annotation.Resource; @@ -20,17 +22,21 @@ import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum; import com.yeshi.fanli.entity.bus.user.TokenRecord; import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum; +import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.redpack.RedPackDetail; import com.yeshi.fanli.entity.redpack.RedPackDetail.RedPackDetailTypeEnum; import com.yeshi.fanli.entity.redpack.RedPackGiveRecord; -import com.yeshi.fanli.exception.redpack.RedPackBalanceException; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; import com.yeshi.fanli.exception.redpack.RedPackGiveRecordException; +import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService; import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService; import com.yeshi.fanli.service.inter.redpack.RedPackConfigService; import com.yeshi.fanli.service.inter.redpack.RedPackDetailService; +import com.yeshi.fanli.service.inter.redpack.RedPackForbidService; import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService; import com.yeshi.fanli.service.inter.user.TokenRecordService; +import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TokenUtil; @@ -38,6 +44,7 @@ import com.yeshi.fanli.util.factory.RedPackDetailFactory; import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; import com.yeshi.fanli.util.rocketmq.MQTopicName; +import com.yeshi.fanli.vo.redpack.RedPackGiveVO; @Service public class RedPackGiveRecordServiceImpl implements RedPackGiveRecordService { @@ -60,8 +67,14 @@ @Resource private UserMoneyMsgNotificationService userMoneyMsgNotificationService; + @Resource + private RedPackForbidService redPackForbidService; + @Resource(name = "producer") private Producer producer; + + @Resource + private UserInfoService userInfoService; @Override public RedPackGiveRecord selectByPrimaryKey(Long id) { @@ -118,29 +131,27 @@ if (uid == null || amount == null) throw new RedPackGiveRecordException(1, "鍙傛暟涓嶆纭�"); + if(redPackForbidService.verifyForbid(uid)) + throw new RedPackGiveRecordException(1, "绾㈠寘鍔熻兘宸茶灏佺"); + String giveMin = redPackConfigService.getValueByKey("give_money_min"); String giveMax = redPackConfigService.getValueByKey("give_money_max"); if (amount.compareTo(new BigDecimal(giveMin)) < 0 || amount.compareTo(new BigDecimal(giveMax)) > 0) throw new RedPackGiveRecordException(1, "璧犻�侀噾棰濊嚦灏�" + giveMin + "鍏冭嚦澶�" + giveMax + "鍏�"); - BigDecimal balance = null; - try { - balance = redPackBalanceService.getBalance(uid); - } catch (RedPackBalanceException e1) { - throw new RedPackGiveRecordException(1, e1.getMsg()); - } - + BigDecimal balance = redPackBalanceService.getBalance(uid); if (balance == null || amount.compareTo(balance) > 0) throw new RedPackGiveRecordException(1, "浣欓涓嶈冻"); Date nowDate = new Date(); + Date endTime = DateUtil.plusDayDate(Constant.TOKEN_DAYS, new Date()); // 璧犻�佽褰� RedPackGiveRecord giveRecord = new RedPackGiveRecord(); giveRecord.setAmount(amount); giveRecord.setGiveUid(uid); giveRecord.setState(RedPackGiveRecord.STATE_INIT); giveRecord.setGiveTime(nowDate); - giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, new Date())); + giveRecord.setEndTime(endTime); redPackGiveRecordMapper.insertSelective(giveRecord); // 鍙d护璁板綍 @@ -149,7 +160,7 @@ tokenRecord.setIdentify(giveRecord.getId() + ""); tokenRecord.setType(TokenTypeEnum.redPack); tokenRecord.setStartTime(nowDate); - tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, new Date())); + tokenRecord.setEndTime(endTime); tokenRecord.setState(0); tokenRecordService.insertSelective(tokenRecord); @@ -170,21 +181,25 @@ try { redPackBalanceService.subRedPack(uid, amount, RedPackDetailFactory.createGiveOthers(giveRecord)); } catch (Exception e) { - throw new RedPackGiveRecordException(1, "绾㈠寘鍒涘缓澶辫触"); - } - - UserRedPackGiftMQMsg msg = new UserRedPackGiftMQMsg(); - msg.setId(giveRecord.getId()); - msg.setUid(uid); - Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.redPackGiftDrawback, - msg); - try { - producer.send(message); - } catch (Exception e) { + LogHelper.errorDetailInfo(e); throw new RedPackGiveRecordException(1, "绾㈠寘鍒涘缓澶辫触"); } - + // 鍙戦�佹秷鎭�(闈炴祴璇曚笅) + if (!Constant.IS_TEST) { + UserRedPackGiftMQMsg msg = new UserRedPackGiftMQMsg(); + msg.setId(giveRecord.getId()); + msg.setUid(uid); + Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.redPackGiftDrawback, msg); + message.setStartDeliverTime(endTime.getTime() + 1000 * 60); // 寤惰繜涓�鍒嗛挓 + try { + producer.send(message); + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + throw new RedPackGiveRecordException(1, "绾㈠寘鍒涘缓澶辫触"); + } + } + return tips; } @@ -227,4 +242,47 @@ return giveRecord; } + + @Override + public List<RedPackGiveVO> getGiveList(int page, int pageSzie, Long uid) { + List<RedPackGiveVO> list = redPackGiveRecordMapper.getGiveList((page-1)*pageSzie, pageSzie, uid); + if (list == null) { + list = new ArrayList<RedPackGiveVO>(); + } + + if (list.isEmpty()) { + return list; + } + + String tips = redPackConfigService.getValueByKey("give_tips"); + String appLink = redPackConfigService.getValueByKey("app_down_link"); + String projectChineseName = Constant.systemCommonConfig.getProjectChineseName(); + + for (RedPackGiveVO record: list) { + Long receiveUid = record.getReceiveUid(); + if (receiveUid != null) { + UserInfo userInfo = userInfoService.selectByPKey(receiveUid); + record.setReceiveName(userInfo.getNickName()); + record.setReceivePortrait(userInfo.getPortrait()); + record.setReceiveTip("棰嗗彇浜嗕綘鐨勭孩鍖�"); + } + TokenRecord token = tokenRecordService.getByTypeAndIdentify(TokenTypeEnum.redPack.name(), + record.getId().toString()); + + String desc = tips; + while (desc.contains("{APP鍚嶇О}")) { + desc = desc.replace("{APP鍚嶇О}", projectChineseName); + } + desc = desc.replace("{鍙d护}", token.getToken()).replace("{涓嬭浇閾炬帴}", appLink).replace("{闈㈤}", record.getAmount().setScale(2).toString()); + record.setDesc(desc); + } + + return list; + } + + @Override + public long countGiveList(Long uid) { + return redPackGiveRecordMapper.countGiveList(uid); + } + } -- Gitblit v1.8.0