From 48077e8c704216f38939cfbf1702f45d7190801d Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期二, 12 十一月 2019 15:26:39 +0800 Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div --- fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java | 78 ++++++++++++++++++++------------------ 1 files changed, 41 insertions(+), 37 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 1a8d80e..bcc3434 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 @@ -3,7 +3,6 @@ import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.List; import javax.annotation.Resource; @@ -17,10 +16,10 @@ 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.redpack.RedPackBalance; 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.exception.redpack.RedPackGiveRecordException; import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService; import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService; @@ -31,6 +30,7 @@ import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TokenUtil; +import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService; import com.yeshi.fanli.util.factory.RedPackDetailFactory; @Service @@ -65,38 +65,43 @@ public void updateByPrimaryKeySelective(RedPackGiveRecord record) { redPackGiveRecordMapper.updateByPrimaryKeySelective(record); } - + @Override - public List<RedPackGiveRecord> overdueList(int count) { - return redPackGiveRecordMapper.overdueList(count); - } - - @Override + @RequestSerializableByKeyService(key = "#id") @Transactional(rollbackFor = Exception.class) - public void overdue(List<RedPackGiveRecord> list) throws Exception { - if (list == null || list.size() == 0) + public void overdueByPrimaryKey(Long id) throws Exception { + if (id == null) return; + RedPackGiveRecord giveRecord = redPackGiveRecordMapper.selectByPrimaryKey(id); + if (giveRecord == null) + return; + + if (giveRecord.getState() != null && giveRecord.getState() != RedPackGiveRecord.STATE_INIT ) + return; + + // 璧犻�佽褰曞け鏁� + RedPackGiveRecord updateRecord = new RedPackGiveRecord(); + updateRecord.setId(giveRecord.getId()); + updateRecord.setState(RedPackGiveRecord.STATE_OVERDUE); + redPackGiveRecordMapper.updateByPrimaryKeySelective(updateRecord); + + // 鍙d护澶辨晥 + tokenRecordService.invalidByRedPack(id); + + // 閫�鍥炵孩鍖� + redPackBalanceService.addRedPack(giveRecord.getGiveUid(), giveRecord.getAmount(), RedPackDetailFactory.createGiveOthersFail(giveRecord)); + + // 閫�鍥炴秷鎭� SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm"); - RedPackGiveRecord updateRecord = null; - for (RedPackGiveRecord giveRecord: list) { - updateRecord = new RedPackGiveRecord(); - updateRecord.setId(giveRecord.getId()); - updateRecord.setState(1); - redPackGiveRecordMapper.updateByPrimaryKeySelective(updateRecord); - - // 閫�鍥炵孩鍖� - redPackBalanceService.addRedPack(giveRecord.getGiveUid(), giveRecord.getAmount(), RedPackDetailFactory.createGiveOthersFail(giveRecord)); - - // 閫�鍥炴秷鎭� - MsgRedPackGiveContentDTO givedto = new MsgRedPackGiveContentDTO(); - givedto.setTitle("浣犺禒閫佺殑绾㈠寘鏈鎴愬姛棰嗗彇"); - givedto.setMoney("楼" + giveRecord.getAmount().setScale(2)); - givedto.setTime(sd.format(new Date())); - givedto.setGiveTime(sd.format(giveRecord.getGiveTime())); - userMoneyMsgNotificationService.redPackMsg(giveRecord.getGiveUid(), MsgTypeMoneyTypeEnum.redPackGiveBack, new Gson().toJson(givedto), "璇峰埌鎴戠殑-绾㈠寘鏌ョ湅"); - } + MsgRedPackGiveContentDTO givedto = new MsgRedPackGiveContentDTO(); + givedto.setTitle("浣犺禒閫佺殑绾㈠寘鏈鎴愬姛棰嗗彇"); + givedto.setMoney("楼" + giveRecord.getAmount().setScale(2)); + givedto.setTime(sd.format(new Date())); + givedto.setGiveTime(sd.format(giveRecord.getGiveTime())); + userMoneyMsgNotificationService.redPackMsg(giveRecord.getGiveUid(), MsgTypeMoneyTypeEnum.redPackGiveBack, new Gson().toJson(givedto), "璇峰埌鎴戠殑-绾㈠寘鏌ョ湅"); + } @@ -111,16 +116,15 @@ if (amount.compareTo(new BigDecimal(giveMin)) < 0 || amount.compareTo(new BigDecimal(giveMax)) > 0) throw new RedPackGiveRecordException(1, "璧犻�侀噾棰濊嚦灏�" + giveMin + "鍏冭嚦澶�" + giveMax + "鍏�"); - RedPackBalance balance = redPackBalanceService.selectByPrimaryKey(uid); - if (balance == null) + BigDecimal balance = null; + try { + balance = redPackBalanceService.getBalance(uid); + } catch (RedPackBalanceException e1) { + throw new RedPackGiveRecordException(1, e1.getMsg()); + } + + if (balance == null || amount.compareTo(balance) > 0) throw new RedPackGiveRecordException(1, "浣欓涓嶈冻"); - - if (balance.getState() != null && balance.getState() == RedPackBalance.STATE_LOCKED) - throw new RedPackGiveRecordException(1, "绾㈠寘宸插皝绂侊紝鎰熻阿浣跨敤"); - - if (balance.getMoney() == null || amount.compareTo(balance.getMoney()) > 0) - throw new RedPackGiveRecordException(1, "浣欓涓嶈冻"); - Date nowDate = new Date(); // 璧犻�佽褰� -- Gitblit v1.8.0