From f7fc64d5ed3d19e131bc84398ae7e801ff30341e Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 10 九月 2019 15:28:19 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java |  243 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 212 insertions(+), 31 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
index 1b4ac74..d251491 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
@@ -1,32 +1,40 @@
 package com.yeshi.fanli.service.impl.integral;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
 
 import javax.annotation.Resource;
 
+import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.DateUtil;
 
 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;
 import com.yeshi.fanli.entity.integral.IntegralTask.FrequencyEnum;
 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.exception.integral.IntegralTaskRecordException;
 import com.yeshi.fanli.exception.user.UserInfoExtraException;
 import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.integral.IntegralDetailService;
 import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
 import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
 import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
+import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
 import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
+import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TimeUtil;
 
 @Service
@@ -44,8 +52,17 @@
 	@Resource
 	private IntegralTaskService integralTaskService;
 
+	@Lazy
 	@Resource
 	private IntegralTaskClassService integralTaskClassService;
+	
+	@Resource
+	private UserOtherMsgNotificationService userOtherMsgNotificationService;
+	
+	@Resource
+	private ConfigService configService;
+	
+	
 
 	@Override
 	public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
@@ -104,14 +121,14 @@
 		}
 
 		if (num > 7) {
-			num = 1;
+			num = 7;
 		}
 		return num;
 	}
 
 	@Override
-	public List<Date> getSignDays(long uid, Long cid) {
-		List<Date> listDate = new ArrayList<Date>();
+	public List<IntegralTaskRecord> getSignDaysRecord(long uid, Long cid) {
+		List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
 		try {
 			// 绛惧埌鏃堕棿姝e簭搴忔煡璇㈣繎7澶╂暟鎹�
 			List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
@@ -123,16 +140,13 @@
 						break; // 澶╂暟鏈繛缁�
 					}
 					date = createTime;
-					listDate.add(record.getCreateTime());
+					listRecord.add(record);
 				}
 			}
 		} catch (Exception e) {
 			LogHelper.errorDetailInfo(e);
 		}
-
-		// 鍊掑簭
-		Collections.reverse(listDate);
-		return listDate;
+		return listRecord;
 	}
 
 	@Override
@@ -192,13 +206,18 @@
 		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) 
+				continue;
+			
 			if (addDetail(uid, record))
 				totalGoldCoin += record.getGoldCoin();
 		}
@@ -251,23 +270,50 @@
 		if (integralTask == null)
 			return false;
 
-		int num = 0;
-		FrequencyEnum frequency = integralTask.getFrequency();
-		if (frequency == FrequencyEnum.everyday) {
-			num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId, TimeUtil.getWholeTime(record.getCreateTime().getTime()));
-		} else if (frequency == FrequencyEnum.onlyOne) {
-			num = 1;
-		}
-
-		if (num <= 0)
-			num = 1;
-
-		String title = taskClass.getName() + "-" + integralTask.getName() + "-" + num + "娆�";
-
 		// 鍔犲叆鏄庣粏
 		IntegralDetail detail = new IntegralDetail();
+		if (UniqueKeyEnum.dailySign == taskClass.getUniqueKey()) {
+			SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
+			Date recordTime = record.getCreateTime();
+			List<IntegralTaskRecord> list = integralTaskRecordMapper.listSignRecordByDateTime(uid, cid,
+					format.format(recordTime));
+			int num = 1;
+			if (list != null && list.size() > 0) {
+				try {
+					Date nextDate = null;
+					for (IntegralTaskRecord tntegralTaskRecord : list) {
+						if (nextDate == null) {
+							nextDate = tntegralTaskRecord.getCreateTime();
+							continue;
+						}
+
+						if (DateUtil.daysBetween2(tntegralTaskRecord.getCreateTime(), nextDate) != 1) {
+							break; // 澶╂暟鏈繛缁�
+						}
+						nextDate = tntegralTaskRecord.getCreateTime();
+						num++;
+					}
+				} catch (ParseException e) {
+					e.printStackTrace();
+				}
+			}
+			detail.setTitle(taskClass.getName() + "-绗�" + num + "澶�");
+		} else {
+			FrequencyEnum frequency = integralTask.getFrequency();
+			if (frequency == FrequencyEnum.everyday) {
+				int num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
+						TimeUtil.getWholeTime(record.getCreateTime().getTime()));
+				if (num <= 0)
+					num = 1;
+				String title = taskClass.getName() + "-" + integralTask.getName() + "-绗�" + num + "娆�";
+				detail.setTitle(title);
+			} else if (frequency == FrequencyEnum.onlyOne) {
+				String title = taskClass.getName() + "-" + integralTask.getName();
+				detail.setTitle(title);
+			}
+		}
+
 		detail.setUid(uid);
-		detail.setTitle(title);
 		detail.setMoney(record.getGoldCoin());
 		detail.setCreateTime(record.getCreateTime());
 		integralDetailService.insertSelective(detail);
@@ -276,12 +322,17 @@
 	}
 
 	@Override
-	public Integer countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
-		if (day == null)
-			return null;
-		Date minTime = new Date(
-				TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
-		Date maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
+	public int countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
+		Date minTime = null;
+		Date maxTime = null;
+		if (day == null) {
+			minTime = new Date(TimeUtil.convertToTimeTemp("1970-01-01", "yyyy-MM-dd"));
+			maxTime = new Date(TimeUtil.convertToTimeTemp("2100-01-01", "yyyy-MM-dd"));
+		} else {
+			minTime = new Date(
+					TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
+			maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
+		}
 		return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
 	}
 
@@ -302,4 +353,134 @@
 		integralTaskRecordMapper.insertSelective(record);
 		return record;
 	}
+
+	@Override
+	public List<IntegralTaskRecord> listByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime,
+			int page, int count) {
+		return integralTaskRecordMapper.listByCidAndUidAndCreateTime(cid, uid, minTime, maxTime, (page - 1) * count,
+				count);
+	}
+
+	@Override
+	public long countByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime) {
+		return integralTaskRecordMapper.countByCidAndUidAndCreateTime(cid, uid, minTime, maxTime);
+	}
+
+	@Override
+	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)) 
+			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)) 
+			return;
+		firstOrderReward(uid, originUid, Integer.parseInt(reward), "浜�", beizu);
+	}
+	
+	
+	@Async()
+	@Override
+	public void firstShareOrderReward(Long uid, String beizu) {
+		if(uid == null)
+			return;
+		
+		String reward = configService.get("first_share_order_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)) 
+			return;
+		firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu);
+	}
+	
+	
+	/**
+	 * 闃熷憳棣栧崟濂栧姳閲戝竵
+	 * @param uid
+	 * @param addGoldCoin
+	 * @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) 
+			uniqueKey = uniqueKey + "-" + originUid;
+		
+		// 鍒ゆ柇鏄惁宸查鍙�
+		IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
+		if (detailRecord != null)
+			return;
+		
+		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+		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());
+			extra.setGoldCoin(goldCoin);
+			userInfoExtraService.saveUserInfoExtra(extra);
+		} catch (UserInfoExtraException e) {
+			LogHelper.errorDetailInfo(e);
+			return;
+		}
+
+		// 閲戝竵璇︽儏
+		IntegralDetail detail = new IntegralDetail();
+		detail.setTitle("閲戝竵濂栧姳");
+		detail.setUid(uid);
+		detail.setMoney(addGoldCoin);
+		detail.setRemark(beizu);
+		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鍏冩椂濂栧姳 ");
+		} else {
+			msgOther.setSource(level + "绾ч槦鍛橀娆′笅鍗曪紝绯荤粺濂栧姳閲戝竵 ");
+			msgOther.setExplain("浠呮柊閭�璇烽槦鍛橀涓嬪崟浣犲緱鍒扮殑濂栭噾涓嶈冻0.01鍏冩椂濂栧姳 ");
+		}
+		userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther);
+	}
 }

--
Gitblit v1.8.0