From 8d84ca36593e33de7e0b604824c471db3587fdb4 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期五, 17 一月 2020 16:53:46 +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/RedPackExchangeServiceImpl.java |  115 ++++++++++++++++++++++++++++-----------------------------
 1 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java
index 2b816ec..2a17ae5 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java
@@ -31,6 +31,7 @@
 import com.yeshi.fanli.service.inter.redpack.RedPackExchangeService;
 import com.yeshi.fanli.service.inter.redpack.RedPackForbidService;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.ThreadUtil;
 import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.util.factory.RedPackDetailFactory;
 
@@ -39,82 +40,78 @@
 
 	@Resource
 	private RedPackExchangeMapper redPackExchangeMapper;
-	
+
 	@Resource
 	private RedPackConfigService redPackConfigService;
-	
+
 	@Resource
 	private RedPackBalanceService redPackBalanceService;
-	
+
 	@Resource
 	private UserMoneyService userMoneyService;
 
 	@Resource
 	private RedPackDetailService redPackDetailService;
-	
+
 	@Resource
 	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
-	
+
 	@Resource
 	private RedPackForbidService redPackForbidService;
-	
-	
+
 	@Override
-	public List<RedPackExchange> query(Integer start, Integer count, String key, Integer state){
+	public List<RedPackExchange> query(Integer start, Integer count, String key, Integer state) {
 		return redPackExchangeMapper.query(start, count, key, state);
 	}
-	
+
 	@Override
-	public Long count(String key, Integer state){
+	public Long count(String key, Integer state) {
 		return redPackExchangeMapper.count(key, state);
 	}
-	
+
 	@Override
 	public Long countByUidAndState(long uid, Integer state) {
 		return redPackExchangeMapper.countByUidAndState(uid, state);
 	}
-	
+
 	@Override
-	public BigDecimal countMoneyByUidAndState(Long uid, Integer state){
+	public BigDecimal countMoneyByUidAndState(Long uid, Integer state) {
 		return redPackExchangeMapper.countMoneyByUidAndState(uid, state);
 	}
-	
+
 	@Override
-	public RedPackExchange selectByPrimaryKey(long id){
+	public RedPackExchange selectByPrimaryKey(long id) {
 		return redPackExchangeMapper.selectByPrimaryKey(id);
 	}
-	
-	
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void exchangeCash(Long uid, BigDecimal amount) throws RedPackExchangeException {
 		if (uid == null || amount == null)
 			throw new RedPackExchangeException(1, "鍙傛暟涓嶆纭�");
-		
-		if(redPackForbidService.verifyForbid(uid))
+
+		if (redPackForbidService.verifyForbid(uid))
 			throw new RedPackExchangeException(1, "绾㈠寘鍔熻兘宸茶灏佺");
-		
+
 		String extractBanlenMin = redPackConfigService.getValueByKey("extract_banlen_min");
-	
-		BigDecimal balance =  redPackBalanceService.getBalance(uid);
+
+		BigDecimal balance = redPackBalanceService.getBalance(uid);
 		if (balance == null || balance.compareTo(new BigDecimal(extractBanlenMin)) < 0)
 			throw new RedPackExchangeException(1, "浣欓涓嶈冻" + extractBanlenMin + "鍏�");
-		
+
 		if (balance.compareTo(amount) < 0)
 			throw new RedPackExchangeException(1, "鎻愮幇浣欓涓嶈冻");
-		
+
 		String moneyMin = redPackConfigService.getValueByKey("extract_money_min");
 		String moneyMax = redPackConfigService.getValueByKey("extract_money_max");
 		if (amount.compareTo(new BigDecimal(moneyMin)) < 0 || amount.compareTo(new BigDecimal(moneyMax)) > 0)
 			throw new RedPackExchangeException(1, "鎻愮幇閲戦鑷冲皯" + moneyMin + "鍏冭嚦澶�" + moneyMax + "鍏�");
-		
-		
+
 		long countToday = redPackExchangeMapper.countTodayByUid(uid);
 		String extractDayMax = redPackConfigService.getValueByKey("extract_day_max");
-		if (!StringUtil.isNullOrEmpty(extractDayMax) && countToday >= Long.parseLong(extractDayMax)) 
+		if (!StringUtil.isNullOrEmpty(extractDayMax) && countToday >= Long.parseLong(extractDayMax))
 			throw new RedPackExchangeException(1, "浠婃棩绾㈠寘鎻愮幇娆℃暟瓒呴檺");
-		
-		
+
 		Date nowDate = new Date();
 		// 鎻愮幇鐢宠
 		RedPackExchange exchange = new RedPackExchange();
@@ -123,7 +120,7 @@
 		exchange.setState(RedPackExchange.STATE_INIT);
 		exchange.setCreateTime(nowDate);
 		redPackExchangeMapper.insertSelective(exchange);
-		
+
 		// 鍑忓皯绾㈠寘
 		try {
 			redPackBalanceService.subRedPack(uid, amount, RedPackDetailFactory.createExchange(exchange));
@@ -131,27 +128,26 @@
 			throw new RedPackExchangeException(1, "绾㈠寘淇℃伅寮傚父");
 		}
 	}
-	
-	
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void passExchange(final long id, AdminUser admin) throws RedPackExchangeException {
 		RedPackExchange record = redPackExchangeMapper.selectByPrimaryKey(id);
-		if (record == null) 
-			throw new RedPackExchangeException(1,"鐢宠璁板綍宸蹭笉瀛樺湪");
+		if (record == null)
+			throw new RedPackExchangeException(1, "鐢宠璁板綍宸蹭笉瀛樺湪");
 
 		if (RedPackExchange.STATE_INIT != record.getState())
-			throw new RedPackExchangeException(1,"璇ョ敵璇峰凡琚鐞嗭紝璇峰埛鏂�");
+			throw new RedPackExchangeException(1, "璇ョ敵璇峰凡琚鐞嗭紝璇峰埛鏂�");
 
-		if(redPackForbidService.verifyForbid(record.getUid()))
+		if (redPackForbidService.verifyForbid(record.getUid()))
 			throw new RedPackExchangeException(1, "绾㈠寘鍔熻兘宸茶灏佺");
-		
+
 		Date nowDate = new Date();
 		record.setAuditId(admin.getId());
 		record.setAuditTime(nowDate);
 		record.setState(RedPackExchange.STATE_SUCCESS);
 		redPackExchangeMapper.updateByPrimaryKeySelective(record);
-		
+
 		// 璧勯噾鏄庣粏-娣诲姞璧勯噾
 		UserMoneyDetail detail = new UserMoneyDetail();
 		detail.setCreateTime(new Date());
@@ -159,13 +155,13 @@
 		detail.setMoney(record.getMoney());
 		detail.setType(UserMoneyDetailTypeEnum.redPackExchange);
 		detail.setTitle(UserMoneyDetailTypeEnum.redPackExchange.getDesc());
-		detail.setDescInfo("浜�"+ TimeUtil.formatDate(record.getCreateTime()) +"鎻愮幇");
+		detail.setDescInfo("浜�" + TimeUtil.formatDate(record.getCreateTime()) + "鎻愮幇");
 		detail.setUpdateTime(new Date());
 		detail.setUserInfo(new UserInfo(record.getUid()));
-		
+
 		// 娣诲姞璧勯噾
 		userMoneyService.addUserMoney(record.getUid(), record.getMoney(), detail);
-		
+
 		// 鏇存柊绾㈠寘鎻愮幇鏄庣粏
 		try {
 			String identifyCode = StringUtil.Md5(RedPackDetailTypeEnum.redExchange.name() + ":" + record.getId());
@@ -175,56 +171,57 @@
 			redPackDetailService.updateByPrimaryKeySelective(updateDetail);
 		} catch (Exception e) {
 			LogHelper.errorDetailInfo(e);
-			throw new RedPackExchangeException(1,"鏇存柊鎻愮幇鏄庣粏鍑洪敊");
+			throw new RedPackExchangeException(1, "鏇存柊鎻愮幇鏄庣粏鍑洪敊");
 		}
-		
-	
-		//娑堟伅
+
+		// 娑堟伅
 		SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
 		String beizu = "绾㈠寘鎻愮幇鎴愬姛鍚庤鍒扳�滄垜鐨�-璐︽埛浣欓鈥濅腑鏌ョ湅";
 		MsgRedPackExchangeContentDTO dto = new MsgRedPackExchangeContentDTO();
 		dto.setTitle("绾㈠寘鎻愮幇");
 		dto.setTime(sd.format(record.getCreateTime()));
-		dto.setHandle("浜哄伐瀹℃牳" + sd.format(new Date())); 
-		dto.setMoney("楼" + record.getMoney().setScale(2));		
+		dto.setHandle("浜哄伐瀹℃牳" + sd.format(new Date()));
+		dto.setMoney("楼" + record.getMoney().setScale(2));
 		dto.setBalance("楼" + redPackBalanceService.getBalance(record.getUid()));
-		userMoneyMsgNotificationService.redPackMsg(record.getUid(), MsgTypeMoneyTypeEnum.redPackExchangePass, new Gson().toJson(dto), beizu);
-		
+		userMoneyMsgNotificationService.redPackMsg(record.getUid(), MsgTypeMoneyTypeEnum.redPackExchangePass,
+				new Gson().toJson(dto), beizu);
+
 	}
-	
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void rejectExchange(long id, String reason, AdminUser admin) throws RedPackExchangeException {
 		RedPackExchange record = redPackExchangeMapper.selectByPrimaryKey(id);
-		if (record == null) 
-			throw new RedPackExchangeException(1,"鐢宠璁板綍宸蹭笉瀛樺湪");
+		if (record == null)
+			throw new RedPackExchangeException(1, "鐢宠璁板綍宸蹭笉瀛樺湪");
 
 		if (RedPackExchange.STATE_INIT != record.getState())
-			throw new RedPackExchangeException(1,"璇ョ敵璇峰凡琚鐞嗭紝璇峰埛鏂�");
-		
+			throw new RedPackExchangeException(1, "璇ョ敵璇峰凡琚鐞嗭紝璇峰埛鏂�");
+
 		record.setReason(reason);
 		record.setAuditTime(new Date());
 		record.setAuditId(admin.getId());
 		record.setState(RedPackExchange.STATE_REJECT);
 		redPackExchangeMapper.updateByPrimaryKeySelective(record);
-		
+
 		// 閫�鍥炵孩鍖�
 		try {
-			redPackBalanceService.addRedPack(record.getUid(), record.getMoney(), RedPackDetailFactory.createExchangeReject(record));
+			redPackBalanceService.addRedPack(record.getUid(), record.getMoney(),
+					RedPackDetailFactory.createExchangeReject(record));
 		} catch (Exception e) {
 			LogHelper.errorDetailInfo(e);
 			throw new RedPackExchangeException(1, "绾㈠寘閫�鍥炴椂鍑洪敊");
 		}
-		
-		//娑堟伅
+
+		// 娑堟伅
 		SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
 		MsgRedPackExchangeContentDTO dto = new MsgRedPackExchangeContentDTO();
 		dto.setTitle("绾㈠寘鎻愮幇");
 		dto.setReason(reason);
 		dto.setHandle(""); // TODO 澶勭悊鏂瑰紡寰呭畾
 		dto.setTime(sd.format(record.getCreateTime()));
-		userMoneyMsgNotificationService.redPackMsg(record.getUid(), MsgTypeMoneyTypeEnum.redPackExchangeReject, new Gson().toJson(dto), null);
+		userMoneyMsgNotificationService.redPackMsg(record.getUid(), MsgTypeMoneyTypeEnum.redPackExchangeReject,
+				new Gson().toJson(dto), null);
 	}
 
 }

--
Gitblit v1.8.0