From 98b1a0affd69bbe63223c21fdd2c404e8bedfccb Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 20 五月 2020 17:25:08 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into 2.1.2

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java |  169 +++++++++++++++++++++++++++----------------------------
 1 files changed, 83 insertions(+), 86 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 0f751a1..ed9cbad 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
@@ -15,8 +15,8 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.DateUtil;
 
+import com.aliyun.openservices.ons.api.Producer;
 import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper;
-import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO;
 import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
 import com.yeshi.fanli.entity.integral.IntegralDetail;
 import com.yeshi.fanli.entity.integral.IntegralTask;
@@ -24,6 +24,7 @@
 import com.yeshi.fanli.entity.integral.IntegralTaskClass;
 import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
 import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
 import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
 import com.yeshi.fanli.exception.user.UserInfoExtraException;
 import com.yeshi.fanli.log.LogHelper;
@@ -34,6 +35,7 @@
 import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService;
 import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
 import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService;
+import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TimeUtil;
 
@@ -55,14 +57,15 @@
 	@Lazy
 	@Resource
 	private IntegralTaskClassService integralTaskClassService;
-	
+
 	@Resource
 	private UserOtherMsgNotificationService userOtherMsgNotificationService;
-	
+
 	@Resource
 	private ConfigService configService;
-	
-	
+
+	@Resource(name = "producer")
+	private Producer producer;
 
 	@Override
 	public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
@@ -75,13 +78,18 @@
 	}
 
 	@Override
+	public void invalidGoldCoin() {
+		integralTaskRecordMapper.invalidGoldCoin();
+	}
+	
+	@Override
 	public void finishedTask(long uid, long cid, long taskId, int goldCoin) {
 		IntegralTaskRecord taskRecord = new IntegralTaskRecord();
 		taskRecord.setUid(uid);
 		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);
@@ -149,7 +157,6 @@
 		return listRecord;
 	}
 
-	
 	@Override
 	public List<IntegralTaskRecord> getSign7DaysRecord(long uid, Long cid) {
 		List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
@@ -165,8 +172,8 @@
 					}
 					date = createTime;
 					listRecord.add(record);
-					
-					if(listRecord.size() >= 7)
+
+					if (listRecord.size() >= 7)
 						break;
 				}
 			}
@@ -175,7 +182,7 @@
 		}
 		return listRecord;
 	}
-	
+
 	@Override
 	public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
 		return integralTaskRecordMapper.listNotReceived(count, uid);
@@ -190,7 +197,7 @@
 	}
 
 	@Override
-	@Transactional(rollbackFor=Exception.class)
+	@Transactional(rollbackFor = Exception.class)
 	public Integer receiveGoldCoinALL(Long uid) throws IntegralTaskRecordException {
 		UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
 		if (userInfoExtra == null)
@@ -205,21 +212,15 @@
 			if (addDetail(uid, record))
 				totalGoldCoin += record.getGoldCoin();
 		}
-		
-		Integer goldCoin = userInfoExtra.getGoldCoin();
-		if (goldCoin == null)
-			goldCoin = 0;
 
-		goldCoin = goldCoin + totalGoldCoin;
-		
 		// 鏇存柊閲戝竵
-		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), goldCoin);
-		
-		return goldCoin;
+		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
+
+		return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin;
 	}
 
-	@Override	
-	@Transactional(rollbackFor=Exception.class)
+	@Override
+	@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涓虹┖");
@@ -229,35 +230,29 @@
 		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 != 0)
 				continue;
-			
+
 			if (addDetail(uid, record))
 				totalGoldCoin += record.getGoldCoin();
 		}
-		
-		Integer goldCoin = userInfoExtra.getGoldCoin();
-		if (goldCoin == null)
-			goldCoin = 0;
 
-		goldCoin = goldCoin + totalGoldCoin;
-		
 		// 鏇存柊閲戝竵
-		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), goldCoin);
+		userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
 
-		return goldCoin;
+		return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin());
 	}
 
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	public boolean addDetail(Long uid, IntegralTaskRecord record) throws IntegralTaskRecordException {
 		Long uid2 = record.getUid();
 		if (uid2 == null || uid.longValue() != uid2.longValue())
@@ -321,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 + "娆�";
@@ -355,6 +350,7 @@
 		return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
 	}
 
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException {
 		if (record == null)
@@ -363,12 +359,15 @@
 		if (record.getCid() == null || record.getTaskId() == null || record.getGoldCoin() == null
 				|| record.getState() == null || record.getUid() == null)
 			throw new IntegralTaskRecordException(2, "鏁版嵁涓嶅畬鎴�");
-
+		Date date = new Date();
 		if (record.getCreateTime() == null)
-			record.setCreateTime(new Date());
+			record.setCreateTime(date);
 
 		if (record.getUpdateTime() == null)
-			record.setUpdateTime(new Date());
+			record.setUpdateTime(date);
+		
+		// 璁剧疆鏈夋晥鏈�
+		record.setEndTime(DateUtil.plusDayDate(Constant.GOLD_COIN_VALID_DAYS, date));
 		integralTaskRecordMapper.insertSelective(record);
 		return record;
 	}
@@ -389,90 +388,91 @@
 	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)) 
+
+		String reward = configService.get(ConfigKeyEnum.firstOrderRewardBoss.getKey());
+		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)) 
+
+		String reward = configService.get(ConfigKeyEnum.firstOrderRewardBossSuper.getKey());
+		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)) 
+
+		String reward = configService.get(ConfigKeyEnum.firstShareOrderReward.getKey());
+		if (StringUtil.isNullOrEmpty(reward))
 			return;
-		firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
+		//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)) 
+
+		String reward = configService.get(ConfigKeyEnum.firstShareOrderRewardBoss.getKey());
+		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;
-		
+
+		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;
@@ -487,19 +487,16 @@
 		detail.setUniqueKey(uniqueKey);
 		detail.setCreateTime(new Date());
 		integralDetailService.insertSelective(detail);
-		
+
 		// 娑堟伅
-		MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
-		msgOther.setTitle("閲戝竵濂栧姳");
-		msgOther.setNum(addGoldCoin + "閲戝竵");
-		msgOther.setTotal(goldCoin + "閲戝竵");
-		if (StringUtil.isNullOrEmpty(level)) {
-			msgOther.setSource("棣栫瑪鍒嗕韩璁㈠崟锛岀郴缁熷鍔遍噾甯� ");
-			msgOther.setExplain("棣栫瑪鍒嗕韩璁㈠崟寰楀埌鐨勫閲戜笉瓒�0.01鍏冩椂濂栧姳 ");
+		if (level.equalsIgnoreCase("涓�") || level.equalsIgnoreCase("1")) {
+			// 鐩存帴绮変笣
+			userOtherMsgNotificationService.goldCoinOrderSubsidyMsg(originUid, addGoldCoin, totalGoldCoin, true);
 		} else {
-			msgOther.setSource(level + "绾ч槦鍛橀娆′笅鍗曪紝绯荤粺濂栧姳閲戝竵 ");
-			msgOther.setExplain("浠呮柊閭�璇烽槦鍛橀涓嬪崟浣犲緱鍒扮殑濂栭噾涓嶈冻0.01鍏冩椂濂栧姳 ");
+			// 闂存帴绮変笣
+			userOtherMsgNotificationService.goldCoinOrderSubsidyMsg(originUid, addGoldCoin, totalGoldCoin, false);
 		}
-		userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther);
+		
 	}
+	 
 }

--
Gitblit v1.8.0