From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 23 五月 2020 09:54:38 +0800
Subject: [PATCH] 足迹、收藏订单兼容新需求

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java |  129 +++++++++++++++++++++++++-----------------
 1 files changed, 76 insertions(+), 53 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
index e86611f..f824710 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
@@ -53,6 +53,7 @@
 import com.yeshi.fanli.entity.common.AdminUser;
 import com.yeshi.fanli.entity.money.UserMoneyDetail;
 import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
 import com.yeshi.fanli.exception.ExtractException;
 import com.yeshi.fanli.exception.NotExistObjectException;
 import com.yeshi.fanli.exception.ObjectStateException;
@@ -67,6 +68,7 @@
 import com.yeshi.fanli.service.inter.money.extract.ExtractService;
 import com.yeshi.fanli.service.inter.money.extract.ExtractWeiXinRecordService;
 import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
+import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
 import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
 import com.yeshi.fanli.service.inter.order.OrderUserStatisticService;
 import com.yeshi.fanli.service.inter.push.PushService;
@@ -77,6 +79,7 @@
 import com.yeshi.fanli.util.GsonUtil;
 import com.yeshi.fanli.util.MoneyBigDecimalUtil;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.ThreadUtil;
 import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
 
@@ -151,6 +154,9 @@
 	@Resource
 	private ExtractWeiXinRecordService extractWeiXinRecordService;
 
+	@Resource
+	private CommonOrderCountService commonOrderCountService;
+
 	@Transactional
 	public Integer addExtract(Extract extract) {
 		Integer integer = extract(extract);
@@ -172,10 +178,9 @@
 		updateExtract.setId(id);
 		updateExtract.setState(Extract.STATE_PROCESSING);
 		extractMapper.updateByPrimaryKeySelective(updateExtract);
-		//TODO 鏂扮増閮ㄧ讲鍚庡垹闄�
 		// 鏀瑰彉璧勯噾璁板綍鐘舵��
-		UserMoneyDetail detail = userMoneyDetailService
-				.selectByTypeAndUidAndIdentifyCode(UserMoneyDetailTypeEnum.extract, find.getUserInfo().getId(), find.getId());
+		UserMoneyDetail detail = userMoneyDetailService.selectByTypeAndUidAndIdentifyCode(
+				UserMoneyDetailTypeEnum.extract, find.getUserInfo().getId(), find.getId());
 		if (detail != null) {
 			UserMoneyDetail update = new UserMoneyDetail(detail.getId());
 			update.setShow(true);
@@ -188,7 +193,7 @@
 		return null;
 	}
 
-	@Transactional(rollbackFor=Exception.class)
+	@Transactional(rollbackFor = Exception.class)
 	public synchronized void rejectExtract(long id, String reason, AdminUser admin)
 			throws ObjectStateException, NotExistObjectException {
 		Extract find = extractMapper.selectByPrimaryKey(id);
@@ -268,9 +273,9 @@
 				&& (System.currentTimeMillis() - history.getCreateTime().getTime()) < 1000 * 60 * 60 * 24 * 7L)
 			return 111;
 
-		final String autoExtract = configService.get("extract_way"); // 鏄惁鑷姩杞处
-		final String maxCount = configService.get("extract_count_day");
-		final String maxMoney = configService.get("extract_money_day");
+		final String autoExtract = configService.get(ConfigKeyEnum.extractWay.getKey()); // 鏄惁鑷姩杞处
+		final String maxCount = configService.get(ConfigKeyEnum.extractDayCount.getKey());
+		final String maxMoney = configService.get(ConfigKeyEnum.extractMoneyDay.getKey());
 
 		UserInfo user = userInfoMapper.selectByPrimaryKeyForUpdate(extract.getUserInfo().getId());
 		// 浣欓涓嶈冻
@@ -291,25 +296,37 @@
 
 		extractMapper.insertSelective(extract);
 
-		ExtractAuditRecord auditRecord = new ExtractAuditRecord();
+		final ExtractAuditRecord auditRecord = new ExtractAuditRecord();
 		auditRecord.setBeforeMoney(user.getMyHongBao());
 		auditRecord.setExtract(extract);
 
 		Date minTime = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 180L);
-		// 缁熻鏁版嵁
-		int orderCount50More = orderUserStatisticService.countOrderCount100MoreByUidAndMinTime(user.getId(), minTime);
 
-		BigDecimal weiQuanOrderFanAmount = orderUserStatisticService.sumWeiQuanOrderFanAmountByUid(user.getId(),
-				minTime);
-		int weiQuanOrderCount = orderUserStatisticService.countWeiQuanOrderByUid(user.getId(), minTime);
-		auditRecord.setExtraInfoStr(new Gson()
-				.toJson(new ExtractOrderStatisticDTO(orderCount50More, weiQuanOrderCount, weiQuanOrderFanAmount, 0)));
 		extractAuditRecordMapper.insertSelective(auditRecord);
+
+		ThreadUtil.run(new Runnable() {
+
+			@Override
+			public void run() {
+				// 缁熻鏁版嵁
+				int less10Count = commonOrderCountService.countOderByUidAndLess10(user.getId());
+				ExtractAuditRecord update = new ExtractAuditRecord();
+				update.setId(auditRecord.getId());
+				int orderCount50More = orderUserStatisticService.countOrderCount100MoreByUidAndMinTime(user.getId(),
+						minTime);
+				BigDecimal weiQuanOrderFanAmount = orderUserStatisticService.sumWeiQuanOrderFanAmountByUid(user.getId(),
+						minTime);
+				int weiQuanOrderCount = orderUserStatisticService.countWeiQuanOrderByUid(user.getId(), minTime);
+				update.setExtraInfoStr(new Gson().toJson(new ExtractOrderStatisticDTO(orderCount50More,
+						weiQuanOrderCount, weiQuanOrderFanAmount, 0, less10Count)));
+				extractAuditRecordMapper.updateByPrimaryKeySelective(update);
+			}
+		});
 
 		// 鏂扮増璧勯噾璇︽儏
 		UserMoneyDetail userMoneyDetail = null;
 		try {
-			userMoneyDetail = UserMoneyDetailFactory.createExtract(extract);
+			userMoneyDetail = UserMoneyDetailFactory.createExtract(extract, null);
 		} catch (UserMoneyDetailException e2) {
 			try {
 				LogHelper.errorDetailInfo(e2);
@@ -417,16 +434,16 @@
 		json.put("payee_type", "ALIPAY_LOGONID");
 		json.put("payee_account", extract.getAccount());
 		json.put("amount", extract.getMoney());
-		json.put("payer_show_name", appName + "App" + "鎻愮幇");
+		json.put("payer_show_name", appName);
 		json.put("payee_real_name", extract.getName());
-		json.put("remark", "鏉ヨ嚜" + appName + "App" + "鐨勬彁鐜�");
+		json.put("remark", "鏉ヨ嚜閲嶅簡蹇渷绉戞妧鏈夐檺鍏徃");
 		request.setBizContent(json.toString());
 		AlipayFundTransToaccountTransferResponse response = null;
 		try {
 			response = alipayClient.execute(request);
 			LogHelper.userErrorInfo("鎻愮幇:鏀粯瀹濋�氳繃鎻愮幇鎴愬姛-" + extract.getId());
 		} catch (AlipayApiException e) {
-			e.printStackTrace();
+			LogHelper.errorDetailInfo(e, "鏀粯瀹濊浆璐﹀紓甯�:" + extract.getId(), "");
 			LogHelper.userErrorInfo("鎻愮幇:鏀粯瀹濇彁鐜板紓甯革細" + response + ",鎻愮幇淇℃伅" + GsonUtil.toJson(extract));
 		}
 
@@ -506,7 +523,7 @@
 	 * @param session
 	 */
 	@Transactional
-	private void extractSuccess(Extract extract) {
+	private void extractSuccess(Extract extract,String alipayNo) {
 		// 鑰佺増鏈姛鑳�
 		// List<MoneyRecord> list = moneyRecordDao.list("from MoneyRecord mr
 		// where mr.extract.id = " + extract.getId());
@@ -529,8 +546,27 @@
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
+
+		UserMoneyDetail detailNew = null;
+		try {
+			detailNew = UserMoneyDetailFactory.createExtract(extract, alipayNo);
+		} catch (UserMoneyDetailException e) {
+			e.printStackTrace();
+		}
+
+		// 澶栨樉璐︽埛鏄庣粏
+		UserMoneyDetail userMoneyDetail = userMoneyDetailMapper.selectByTypeAndUidAndIdentifyCode(
+				UserMoneyDetailTypeEnum.extractNew, extract.getUserInfo().getId(), extract.getId());
+		if (userMoneyDetail != null) {
+			UserMoneyDetail detail = new UserMoneyDetail(userMoneyDetail.getId());
+			detail.setShow(true);
+			detail.setUpdateTime(new Date());
+			if (detailNew != null)
+				detail.setDescInfo(detailNew.getDescInfo());
+			userMoneyDetailMapper.updateByPrimaryKeySelective(detail);
+		}
 		// 鏂扮増閫氱煡
-		userMoneyMsgNotificationService.extractSuccess(extract);
+		userMoneyMsgNotificationService.extractSuccess(extract, alipayNo);
 	}
 
 	/**
@@ -541,7 +577,7 @@
 		return extractMapper.selectByPrimaryKey(id);
 	}
 
-	@Transactional(rollbackFor=Exception.class)
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void checkExtract(Long uid) throws ExtractException {
 		BigDecimal compensateMoney = extractMapper.computeCompensateByUid(uid);
@@ -563,8 +599,10 @@
 		// 鑾峰彇鎻愮幇锛岃幏鍙栨彁鐜伴獙璇�
 		List<UserMoneyDetailTypeEnum> typeList = new ArrayList<>();
 		typeList.add(UserMoneyDetailTypeEnum.extract);
+		typeList.add(UserMoneyDetailTypeEnum.extractNew);
 		typeList.add(UserMoneyDetailTypeEnum.extractReject);
 		typeList.add(UserMoneyDetailTypeEnum.extractVerify);
+		typeList.add(UserMoneyDetailTypeEnum.extractVerifyNew);
 		BigDecimal extractMoney = userMoneyDetailService.statisticUserTypeMoneyWithDate(uid, typeList, new Date(0),
 				now);
 		extractMoney = extractMoney.abs();
@@ -584,7 +622,7 @@
 		BigDecimal after = hongBaoMoney.subtract(extractMoney.add(weiqaunMoney).add(balance).add(compensateMoney));
 
 		if (after.compareTo(new BigDecimal("0")) != 0)
-			throw new ExtractException(2, "缁撶畻璧勯噾寮傚父");
+			throw new ExtractException(2, "缁撶畻璧勯噾寮傚父锛�" + after);
 	}
 
 	@Override
@@ -633,7 +671,7 @@
 		if (response.isSuccess()) {
 			String code = response.getCode();
 			if ("10000".equals(code)) {
-				extractSuccess(extract);
+				extractSuccess(extract,response.getOrderId());
 			} else {
 				extractFail(extract, response.getSubMsg());
 			}
@@ -695,23 +733,13 @@
 			extractAuditRecordMapper.updateByPrimaryKeySelective(auditRecord);
 		}
 
-		// 澶栨樉璐︽埛鏄庣粏
-		UserMoneyDetail userMoneyDetail = userMoneyDetailMapper.selectByTypeAndUidAndIdentifyCode(
-				UserMoneyDetailTypeEnum.extract, extract.getUserInfo().getId(), extract.getId());
-		if (userMoneyDetail != null) {
-			UserMoneyDetail detail = new UserMoneyDetail(userMoneyDetail.getId());
-			detail.setShow(true);
-			detail.setUpdateTime(new Date());
-			userMoneyDetailMapper.updateByPrimaryKeySelective(detail);
-		}
-
 	}
 
 	@Transactional
 	@Override
 	public void testExtractSuccess(Long id) {
 		Extract extract = extractMapper.selectByPrimaryKey(id);
-		extractSuccess(extract);
+		extractSuccess(extract,null);
 		Long uid = extract.getUserInfo().getId();
 
 		// 鏇存柊瀹℃牳璁板綍
@@ -883,10 +911,6 @@
 			LogHelper.errorDetailInfo(e);
 		}
 
-		// 4銆佸彂閫佹秷鎭�氱煡
-		String desc = "涓轰繚闅滀綘鐨勮处鎴蜂綑棰濆畨鍏紝鑷姩鎻愮幇閲戦灏嗕笉浼氶珮浜�5鍏�";
-		String beizu = "璐︽埛涓墿浣欎綑棰濊鍦ㄦ湰App鍐呭畬鎴愭彁鐜�";
-		userMoneyMsgNotificationService.extractAuto(extractRecord, "鏈鍙�-鎻愮幇涓�", desc, beizu);
 	}
 
 	private boolean parseSendResult(String result) {
@@ -1086,8 +1110,7 @@
 		}
 		return listOpendIDs;
 	}
-	
-	
+
 	@Override
 	public List<UserInfo> preAutoUserTo1212() throws Exception {
 		int page = 0;
@@ -1139,7 +1162,7 @@
 		}
 		return list;
 	}
-	
+
 	@Override
 	public List<String> getAutoExtractOpenIdsTo1212() throws Exception {
 		int page = 0;
@@ -1226,11 +1249,6 @@
 			// 璧勯噾璁$畻
 			userMoneyService.subUserMoney(userInfo.getId(), money, detail);
 
-			// 4銆佸彂閫佹秷鎭�氱煡
-			String desc = "涓轰繚闅滀綘鐨勮处鎴蜂綑棰濆畨鍏紝鑷姩鎻愮幇閲戦灏嗕笉浼氶珮浜�5鍏�";
-			String beizu = "璐︽埛涓墿浣欎綑棰濊鍦ㄦ湰App鍐呭畬鎴愭彁鐜�";
-			userMoneyMsgNotificationService.extractAuto(extractRecord, "鏈鍙�-鎻愮幇涓�", desc, beizu);
-
 			// 婊¤冻鏉′欢杩斿洖淇℃伅
 			return userInfo;
 		}
@@ -1316,8 +1334,6 @@
 		extractWeiXinRecordService.updateByPrimaryKeySelective(updeteRecord);
 
 		if (ExtractWeiXinRecord.RECEIVED.equals(status)) {
-			// 鍙戦�佹秷鎭�氱煡
-			userMoneyMsgNotificationService.extractAuto(record, "宸查鍙�-宸叉彁鐜�", null, null);
 		} else if (ExtractWeiXinRecord.REFUND.equals(status)) {
 			// 璧勯噾鏄庣粏
 			UserMoneyDetail detail = new UserMoneyDetail();
@@ -1329,13 +1345,20 @@
 			detail.setType(UserMoneyDetailTypeEnum.extractAutoWXRefund);
 			detail.setUpdateTime(new Date());
 			detail.setUserInfo(new UserInfo(record.getUid()));
-
 			// 璧勯噾璁$畻
 			userMoneyService.addUserMoney(record.getUid(), record.getMoney(), detail);
-
-			// 鍙戦�佹秷鎭�氱煡
-			userMoneyMsgNotificationService.extractAuto(record, "宸查��鍥�-浣欓涓�", null, null);
 		}
 	}
 
+	
+	@Override
+	public List<Extract> getExtractSucceedRecord(int page, int pageSize, Long uid) {
+		return extractMapper.getExtractSucceedRecord((page-1)*pageSize, pageSize, uid);
+	}
+	
+	@Override
+	public long countExtractSucceedRecord(Long uid) {
+       Long count = extractMapper.countExtractSucceedRecord(uid);
+       return count== null? 0 : count;
+	}
 }

--
Gitblit v1.8.0