From 3ac30b4c17cf071ce9c66a59c069ab83efae6d2d Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 14 十月 2019 17:44:13 +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/user/integral/IntegralTaskRecordServiceImpl.java |  117 +++++++++++++++++++++++-----------------------------------
 1 files changed, 46 insertions(+), 71 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 a9e170a..697d4a4 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
@@ -55,14 +55,12 @@
 	@Lazy
 	@Resource
 	private IntegralTaskClassService integralTaskClassService;
-	
+
 	@Resource
 	private UserOtherMsgNotificationService userOtherMsgNotificationService;
-	
+
 	@Resource
 	private ConfigService configService;
-	
-	
 
 	@Override
 	public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
@@ -149,7 +147,6 @@
 		return listRecord;
 	}
 
-	
 	@Override
 	public List<IntegralTaskRecord> getSign7DaysRecord(long uid, Long cid) {
 		List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
@@ -165,8 +162,8 @@
 					}
 					date = createTime;
 					listRecord.add(record);
-					
-					if(listRecord.size() >= 7)
+
+					if (listRecord.size() >= 7)
 						break;
 				}
 			}
@@ -175,7 +172,7 @@
 		}
 		return listRecord;
 	}
-	
+
 	@Override
 	public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
 		return integralTaskRecordMapper.listNotReceived(count, uid);
@@ -190,9 +187,9 @@
 	}
 
 	@Override
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	public Integer receiveGoldCoinALL(Long uid) throws IntegralTaskRecordException {
-		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+		UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
 		if (userInfoExtra == null)
 			throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
 
@@ -206,67 +203,47 @@
 				totalGoldCoin += record.getGoldCoin();
 		}
 
-		Integer goldCoin = userInfoExtra.getGoldCoin();
-		if (goldCoin == null)
-			goldCoin = 0;
+		// 鏇存柊閲戝竵
+		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
 
-		UserInfoExtra extra = new UserInfoExtra();
-		extra.setId(userInfoExtra.getId());
-		extra.setGoldCoin(goldCoin + totalGoldCoin);
-		try {
-			userInfoExtraService.saveUserInfoExtra(extra);
-		} catch (UserInfoExtraException e) {
-			throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
-		}
-
-		return extra.getGoldCoin();
+		return (userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin()) + totalGoldCoin;
 	}
 
 	@Override
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	public Integer receiveGoldCoin(Long uid, Set<Long> idList) throws IntegralTaskRecordException {
 		if (idList == null || idList.size() == 0) {
 			throw new IntegralTaskRecordException(1, "id涓虹┖");
 		}
 
-		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+		UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
 		if (userInfoExtra == null) {
 			throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
 		}
- 
+
 		Integer totalGoldCoin = 0;
 		for (Long id : idList) {
 			IntegralTaskRecord record = integralTaskRecordMapper.selectByPrimaryKey(id);
 			if (record == null)
 				continue;
-			
+
 			// 宸查鍙�
 			Integer state = record.getState();
-			if (state != null && state == 1) 
+			if (state != null && state == 1)
 				continue;
-			
+
 			if (addDetail(uid, record))
 				totalGoldCoin += record.getGoldCoin();
 		}
 
-		Integer goldCoin = userInfoExtra.getGoldCoin();
-		if (goldCoin == null)
-			goldCoin = 0;
+		// 鏇存柊閲戝竵
+		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
 
-		UserInfoExtra extra = new UserInfoExtra();
-		extra.setId(userInfoExtra.getId());
-		extra.setGoldCoin(goldCoin + totalGoldCoin);
-		try {
-			userInfoExtraService.saveUserInfoExtra(extra);
-		} catch (UserInfoExtraException e) {
-			throw new IntegralTaskRecordException(1, "鐢ㄦ埛淇℃伅涓嶅叏");
-		}
-
-		return extra.getGoldCoin();
+		return totalGoldCoin+(userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin());
 	}
 
+	@Transactional
 	public boolean addDetail(Long uid, IntegralTaskRecord record) throws IntegralTaskRecordException {
-
 		Long uid2 = record.getUid();
 		if (uid2 == null || uid.longValue() != uid2.longValue())
 			return false; // 鐢ㄦ埛id涓嶇鍚�
@@ -329,7 +306,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 + "娆�";
@@ -397,85 +374,83 @@
 	public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) {
 		return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
 	}
-	
-	
+
 	@Async()
 	@Override
 	public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) {
 		if (uid == null || originUid == null)
 			return;
-		
+
 		String reward = configService.get("first_order_reward_boss");
-		if (StringUtil.isNullOrEmpty(reward)) 
+		if (StringUtil.isNullOrEmpty(reward))
 			return;
 		firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
 	}
-	
+
 	@Async()
 	@Override
 	public void firstRebateOrderRewardBossSuper(Long uid, Long originUid, String beizu) {
 		if (uid == null || originUid == null)
 			return;
-		
+
 		String reward = configService.get("first_order_reward_boss_super");
-		if (StringUtil.isNullOrEmpty(reward)) 
+		if (StringUtil.isNullOrEmpty(reward))
 			return;
 		firstOrderReward(uid, originUid, Integer.parseInt(reward), "浜�", beizu);
 	}
-	
-	
+
 	@Async()
 	@Override
 	public void firstShareOrderReward(Long uid, String beizu) {
-		if(uid == null)
+		if (uid == null)
 			return;
-		
+
 		String reward = configService.get("first_share_order_reward");
-		if (StringUtil.isNullOrEmpty(reward)) 
+		if (StringUtil.isNullOrEmpty(reward))
 			return;
 		firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
 	}
-	
-	
+
 	@Async()
 	@Override
 	public void firstSharerOrderRewardBoss(Long uid, Long originUid, String beizu) {
 		if (uid == null || originUid == null)
 			return;
-		
+
 		String reward = configService.get("first_share_order_reward_boss");
-		if (StringUtil.isNullOrEmpty(reward)) 
+		if (StringUtil.isNullOrEmpty(reward))
 			return;
 		firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
 	}
-	
-	
+
 	/**
 	 * 闃熷憳棣栧崟濂栧姳閲戝竵
+	 * 
 	 * @param uid
 	 * @param addGoldCoin
-	 * @param level 鎵�灞炲摢绾ч槦鍛�
+	 * @param level
+	 *            鎵�灞炲摢绾ч槦鍛�
 	 * @param beizu
 	 */
 	private void firstOrderReward(Long uid, Long originUid, Integer addGoldCoin, String level, String beizu) {
-		String uniqueKey = "firstOrder-"+ uid.toString();
-		if (originUid != null) 
+		String uniqueKey = "firstOrder-" + uid.toString();
+		if (originUid != null)
 			uniqueKey = uniqueKey + "-" + originUid;
-		
+
 		// 鍒ゆ柇鏄惁宸查鍙�
 		IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
 		if (detailRecord != null)
 			return;
-		
+
 		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
-		if (userInfoExtra == null) 
+		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());
@@ -495,7 +470,7 @@
 		detail.setUniqueKey(uniqueKey);
 		detail.setCreateTime(new Date());
 		integralDetailService.insertSelective(detail);
-		
+
 		// 娑堟伅
 		MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
 		msgOther.setTitle("閲戝竵濂栧姳");

--
Gitblit v1.8.0