From 08d5529087390663115d326190635e4a4997acf2 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 28 八月 2019 17:05:47 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java |  286 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 163 insertions(+), 123 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
index 73e276d..684416c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -310,6 +310,9 @@
 			return null;
 		}
 
+		// 杩囨湡鍒�
+		updateInvalidSate(uid);
+		
 		// 閫�鍥炲埜
 		sendBackTimeOutCoupon(uid);
 		
@@ -573,6 +576,9 @@
 			throw new UserSystemCouponException(1, "鐢ㄦ埛鏈櫥褰�");
 		}
 
+		// 杩囨湡鍒�
+		updateInvalidSate(uid);
+		
 		// 閫�鍥炲埜
 		sendBackTimeOutCoupon(uid);
 
@@ -598,6 +604,9 @@
 			throw new UserSystemCouponException(1, "鍟嗗搧ID涓虹┖");
 		}
 
+		// 杩囨湡鍒�
+		updateInvalidSate(uid);
+		
 		// 閫�鍥炲埜
 		sendBackTimeOutCoupon(uid);
 		
@@ -1224,76 +1233,7 @@
 		return userSystemCouponMapper.getCounponNowInvalid(count);
 	}
 	
-
-	@Override
-	public void updateCounponInvalid(List<UserSystemCoupon> list) {
-		if (list == null || list.size() == 0) {
-			return;
-		}
-
-		for (UserSystemCoupon userSystemCoupon : list) {
-			UserSystemCoupon userCoupon = new UserSystemCoupon();
-			userCoupon.setUpdateTime(new Date());
-			userSystemCoupon.setState(UserSystemCoupon.STATE_OVERDUE);
-			userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
-
-			SystemCoupon baseCoupon = userSystemCoupon.getSystemCoupon();
-			if (baseCoupon == null) {
-				continue;
-			}
-			
-			baseCoupon = systemCouponService.selectByPrimaryKey(baseCoupon.getId());
-			if (baseCoupon == null || baseCoupon.getId() == null) {
-				continue;
-			}
-
-			// 娑堟伅鎺ㄩ��
-			try {
-				if (baseCoupon.getType() == CouponTypeEnum.welfareFreeCoupon) {
-					userOtherMsgNotificationService.welfareCouponAlreadyOutOfDate(userSystemCoupon);
-				} else if (baseCoupon.getType() == CouponTypeEnum.freeCoupon) {
-					userOtherMsgNotificationService.freeSheetCouponAlreadyOutOfDate(userSystemCoupon);
-				} else if (baseCoupon.getType() == CouponTypeEnum.rebatePercentCoupon) {
-					userOtherMsgNotificationService.rewardCouponAlreadyOutOfDate(userSystemCoupon);
-				}else if (baseCoupon.getType() == CouponTypeEnum.freeCouponBuy) {
-					userOtherMsgNotificationService.outOfDate(userSystemCoupon, MsgTypeOtherTypeEnum.freeCouponBuy);
-				} else if (baseCoupon.getType() == CouponTypeEnum.freeCouponGive) {
-					userOtherMsgNotificationService.outOfDate(userSystemCoupon, MsgTypeOtherTypeEnum.freeCouponGive);
-				}
-			} catch (Exception e) {
-				try {
-					LogHelper.errorDetailInfo(e);
-				} catch (Exception e1) {
-					e1.printStackTrace();
-				}
-			}
-		}
-	}
-
-	@Transactional
-	@Override
-	public void sendBackTimeOutCoupon(Long uid) {
-		// 瓒呰繃10鍒嗛挓   鏈鍖归厤鐨勫埜
-		List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 600L);
-		if (list == null || list.size() == 0) {
-			return;
-		}
-
-		for (UserSystemCouponRecord couponRecord : list) {
-			// 鏇存柊鐘舵�侊細鍖归厤瓒呮椂
-			couponRecord.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
-			couponRecord.setUpdateTime(new Date());
-			userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
-
-			UserSystemCoupon userSystemCoupon = couponRecord.getUserSystemCoupon();
-			// 鐘舵�佸垵濮嬪寲
-			userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
-			userSystemCoupon.setUseTime(null);
-			userSystemCoupon.setUpdateTime(new Date());
-			userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
-		}
-	}
-
+	
 	@Transactional
 	@Override
 	public boolean updateCouponRecordUsed(Long uid, String orderNo, BigDecimal payment, Long auctionId)
@@ -1372,56 +1312,7 @@
 		return isfree;
 	}
 
-	/**
-	 * 閫�鍥炲埜 鍒濆鏁版嵁
-	 * 
-	 * @param userSystemCoupon
-	 */
-	public void sendBackCoupon(UserSystemCoupon userCoupon, UserSystemCouponRecord record) throws Exception {
-		if (userCoupon == null)
-			return;
-			
-		Integer state = userCoupon.getState();
-		if (state != UserSystemCoupon.STATE_IN_USE) 
-			return;
-		
-		Date now = new Date();
-		Date endTime = userCoupon.getEndTime();
-		if (endTime != null && endTime.getTime() < now.getTime()) {
-			// 杩囨湡
-			List<UserSystemCoupon> list = new ArrayList<UserSystemCoupon>();
-			list.add(userCoupon);
-			updateCounponInvalid(list);
-			return;
-		}
-		
-		// 閫�鍥炲埜
-		UserSystemCoupon userSystemCoupon = new UserSystemCoupon();
-		userSystemCoupon.setId(userCoupon.getId());
-		userSystemCoupon.setGive(false);
-		userSystemCoupon.setUseTime(null);
-		userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
-		userSystemCoupon.setUpdateTime(new Date());
-		userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
-		
-		// 浣跨敤璁板綍
-		if  (record != null) {
-			UserSystemCouponRecord useRecordUpdate = new UserSystemCouponRecord();
-			useRecordUpdate.setId(record.getId());
-			useRecordUpdate.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
-			useRecordUpdate.setUpdateTime(new Date());
-			userSystemCouponRecordService.updateByPrimaryKeySelective(useRecordUpdate);
-			
-			if (CouponTypeEnum.welfareFreeCoupon.name().equals(record.getCouponType())) {
-				userOtherMsgNotificationService.welfareCouponDrawBack(userSystemCoupon, record.getOrderNo());
-			} else if (CouponTypeEnum.freeCoupon.name().equals(record.getCouponType())) {
-				userOtherMsgNotificationService.freeSheetCouponDrawBack(userSystemCoupon, record.getOrderNo());
-			} else if (CouponTypeEnum.freeCouponBuy.name().equals(record.getCouponType())) {
-				userOtherMsgNotificationService.couponDrawBack(userSystemCoupon, record.getOrderNo(), MsgTypeOtherTypeEnum.freeCouponBuy);
-			}
-		}
-		
-	}
+	
 
 	@Override
 	@Transactional
@@ -1715,9 +1606,14 @@
 	@Override
 	public List<UserSystemCouponVO> getCouponList(long start, int count, Long uid)
 			throws UserSystemCouponException, Exception {
+	
+		// 杩囨湡鍒�
+		updateInvalidSate(uid);
+		
 		// 閫�鍥炲埜
 		sendBackTimeOutCoupon(uid);
 
+		
 		List<UserSystemCouponVO> listVO = userSystemCouponMapper.getUserCouponVOList(start, count, uid);
 		if (listVO == null || listVO.size() == 0) {
 			return listVO;
@@ -1902,7 +1798,7 @@
 					Date useTime = userCouponVO.getUseTime();
 					if (useTime != null) {
 						Map<String, Object> remainDays = new HashMap<String, Object>();
-						remainDays.put("content", "浜�" + sdf.format(useTime) + "鎴愬姛璧犻��");
+						remainDays.put("content", "浜�" + sdf.format(useTime) + "璧犻��");
 						remainDays.put("fontColor", "#CCCCCC");
 						userCouponVO.setRemainDays(remainDays);
 					}
@@ -1910,7 +1806,7 @@
 					Date useTime = userCouponVO.getUseTime();
 					if (useTime != null) {
 						Map<String, Object> remainDays = new HashMap<String, Object>();
-						remainDays.put("content", "浜�" + sdf.format(useTime) + "鎴愬姛浣跨敤");
+						remainDays.put("content", "浜�" + sdf.format(useTime) + "浣跨敤");
 						remainDays.put("fontColor", "#CCCCCC");
 						userCouponVO.setRemainDays(remainDays);
 					}
@@ -2069,6 +1965,139 @@
 	}
 
 	
+	@Transactional
+	@Override
+	public void updateInvalidSate(Long uid) {
+		List<UserSystemCoupon> list = userSystemCouponMapper.getCounponNowInvalidByUid(uid);
+		if (list == null || list.size() == 0) {
+			return;
+		}
+		updateCounponInvalid(list);
+	}
+	
+	
+	@Override
+	public void updateCounponInvalid(List<UserSystemCoupon> list) {
+		if (list == null || list.size() == 0) {
+			return;
+		}
+
+		for (UserSystemCoupon userSystemCoupon : list) {
+			UserSystemCoupon userCoupon = new UserSystemCoupon();
+			userCoupon.setUpdateTime(new Date());
+			userSystemCoupon.setState(UserSystemCoupon.STATE_OVERDUE);
+			userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
+
+			SystemCoupon baseCoupon = userSystemCoupon.getSystemCoupon();
+			if (baseCoupon == null) {
+				continue;
+			}
+			
+			baseCoupon = systemCouponService.selectByPrimaryKey(baseCoupon.getId());
+			if (baseCoupon == null || baseCoupon.getId() == null) {
+				continue;
+			}
+
+			// 娑堟伅鎺ㄩ��
+			try {
+				if (baseCoupon.getType() == CouponTypeEnum.welfareFreeCoupon) {
+					userOtherMsgNotificationService.welfareCouponAlreadyOutOfDate(userSystemCoupon);
+				} else if (baseCoupon.getType() == CouponTypeEnum.freeCoupon) {
+					userOtherMsgNotificationService.freeSheetCouponAlreadyOutOfDate(userSystemCoupon);
+				} else if (baseCoupon.getType() == CouponTypeEnum.rebatePercentCoupon) {
+					userOtherMsgNotificationService.rewardCouponAlreadyOutOfDate(userSystemCoupon);
+				}else if (baseCoupon.getType() == CouponTypeEnum.freeCouponBuy) {
+					userOtherMsgNotificationService.outOfDate(userSystemCoupon, MsgTypeOtherTypeEnum.freeCouponBuy);
+				} else if (baseCoupon.getType() == CouponTypeEnum.freeCouponGive) {
+					userOtherMsgNotificationService.outOfDate(userSystemCoupon, MsgTypeOtherTypeEnum.freeCouponGive);
+				}
+			} catch (Exception e) {
+				try {
+					LogHelper.errorDetailInfo(e);
+				} catch (Exception e1) {
+					e1.printStackTrace();
+				}
+			}
+		}
+	}
+	
+	
+	/**
+	 * 閫�鍥炲埜 鍒濆鏁版嵁
+	 * 
+	 * @param userSystemCoupon
+	 */
+	public void sendBackCoupon(UserSystemCoupon userCoupon, UserSystemCouponRecord record) throws Exception {
+		if (userCoupon == null)
+			return;
+			
+		Integer state = userCoupon.getState();
+		if (state != UserSystemCoupon.STATE_IN_USE) 
+			return;
+		
+		Date now = new Date();
+		Date endTime = userCoupon.getEndTime();
+		if (endTime != null && endTime.getTime() < now.getTime()) {
+			// 杩囨湡
+			List<UserSystemCoupon> list = new ArrayList<UserSystemCoupon>();
+			list.add(userCoupon);
+			updateCounponInvalid(list);
+			return;
+		}
+		
+		// 閫�鍥炲埜
+		UserSystemCoupon userSystemCoupon = new UserSystemCoupon();
+		userSystemCoupon.setId(userCoupon.getId());
+		userSystemCoupon.setGive(false);
+		userSystemCoupon.setUseTime(null);
+		userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
+		userSystemCoupon.setUpdateTime(new Date());
+		userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
+		
+		// 浣跨敤璁板綍
+		if  (record != null) {
+			UserSystemCouponRecord useRecordUpdate = new UserSystemCouponRecord();
+			useRecordUpdate.setId(record.getId());
+			useRecordUpdate.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
+			useRecordUpdate.setUpdateTime(new Date());
+			userSystemCouponRecordService.updateByPrimaryKeySelective(useRecordUpdate);
+			
+			if (CouponTypeEnum.welfareFreeCoupon.name().equals(record.getCouponType())) {
+				userOtherMsgNotificationService.welfareCouponDrawBack(userSystemCoupon, record.getOrderNo());
+			} else if (CouponTypeEnum.freeCoupon.name().equals(record.getCouponType())) {
+				userOtherMsgNotificationService.freeSheetCouponDrawBack(userSystemCoupon, record.getOrderNo());
+			} else if (CouponTypeEnum.freeCouponBuy.name().equals(record.getCouponType())) {
+				userOtherMsgNotificationService.couponDrawBack(userSystemCoupon, record.getOrderNo(), MsgTypeOtherTypeEnum.freeCouponBuy);
+			}
+		}
+	}
+	
+	
+	@Transactional
+	@Override
+	public void sendBackTimeOutCoupon(Long uid) {
+		// 瓒呰繃10鍒嗛挓   鏈鍖归厤鐨勫埜
+		List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 600L);
+		if (list == null || list.size() == 0) {
+			return;
+		}
+
+		for (UserSystemCouponRecord couponRecord : list) {
+			// 鏇存柊鐘舵�侊細鍖归厤瓒呮椂
+			couponRecord.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
+			couponRecord.setUpdateTime(new Date());
+			userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
+
+			// 鐘舵�佸垵濮嬪寲
+			UserSystemCoupon userSystemCoupon = couponRecord.getUserSystemCoupon();
+			userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
+			userSystemCoupon.setUseTime(null);
+			userSystemCoupon.setUpdateTime(new Date());
+			userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
+		}
+	}
+
+	
 	@Override
 	public void sendBackGiveCoupon(List<UserSystemCouponGiveRecord> overdueList) {
 		for (UserSystemCouponGiveRecord record: overdueList) {
@@ -2128,11 +2157,12 @@
 			if (systemCoupon == null)
 				continue;
 			
+			
+			// 閫�鍥炴秷鎭�
 			String couponName = systemCoupon.getName();
 			if (CouponTypeEnum.freeCouponGive == systemCoupon.getType())
 				couponName = "鍏嶅崟鍒�";
 			
-			// 閫�鍥炴秷鎭�
 			String beiZhu = "璇峰埌鎴戠殑-绂忓埄涓績鏌ョ湅";
 			SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
 			MsgOtherGiveContentDTO msgOther = new MsgOtherGiveContentDTO();
@@ -2148,6 +2178,9 @@
 	
 	@Override
 	public boolean getIncludeExchange(Long uid) {
+		// 杩囨湡鍒�
+		updateInvalidSate(uid);
+		
 		String percent = configService.get("exchange_rebate_percent");
 		if (StringUtil.isNullOrEmpty(percent)) 
 			percent = "35";
@@ -2160,6 +2193,9 @@
 	
 	@Override
 	public boolean getIncludeNotExchange(Long uid) {
+		// 杩囨湡鍒�
+		updateInvalidSate(uid);
+		
 		String percent = configService.get("exchange_rebate_percent");
 		if (StringUtil.isNullOrEmpty(percent)) 
 			percent = "35";
@@ -2172,6 +2208,10 @@
 	
 	@Override
 	public List<UserSystemCouponVO> listIncludeNotExchange(Long uid) throws Exception{
+		// 杩囨湡鍒�
+		updateInvalidSate(uid);
+		
+		// 閫�鍥炲埜
 		sendBackTimeOutCoupon(uid);
 		
 		String percent = configService.get("exchange_rebate_percent");

--
Gitblit v1.8.0