From ee1d39f11b9483b64a88029f1755a6e7166fea15 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期日, 26 四月 2020 16:49:21 +0800 Subject: [PATCH] 等级显示问题 --- fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java | 214 +++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 172 insertions(+), 42 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 4a5a8cd..f226518 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,12 +178,22 @@ updateExtract.setId(id); updateExtract.setState(Extract.STATE_PROCESSING); extractMapper.updateByPrimaryKeySelective(updateExtract); + // 鏀瑰彉璧勯噾璁板綍鐘舵�� + UserMoneyDetail detail = userMoneyDetailService.selectByTypeAndUidAndIdentifyCode( + UserMoneyDetailTypeEnum.extract, find.getUserInfo().getId(), find.getId()); + if (detail != null) { + UserMoneyDetail update = new UserMoneyDetail(detail.getId()); + update.setShow(true); + update.setUpdateTime(new Date()); + userMoneyDetailMapper.updateByPrimaryKeySelective(update); + } + transfer(find, admin); // 鎻愮幇閫氳繃锛屾敮浠樺疂杞处 return null; } - @Transactional + @Transactional(rollbackFor = Exception.class) public synchronized void rejectExtract(long id, String reason, AdminUser admin) throws ObjectStateException, NotExistObjectException { Extract find = extractMapper.selectByPrimaryKey(id); @@ -257,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()); // 浣欓涓嶈冻 @@ -280,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); @@ -317,7 +345,6 @@ LogHelper.userInfo("uid=" + user.getId() + ",鎻愪氦杞处鐢宠!"); } else {// 鏆傛椂涓嶈嚜鍔ㄦ彁鐜� // transfer(extract, null); - ; } return null; } @@ -416,7 +443,7 @@ response = alipayClient.execute(request); LogHelper.userErrorInfo("鎻愮幇:鏀粯瀹濋�氳繃鎻愮幇鎴愬姛-" + extract.getId()); } catch (AlipayApiException e) { - e.printStackTrace(); + LogHelper.errorDetailInfo(e, "鏀粯瀹濊浆璐﹀紓甯�:" + extract.getId(), ""); LogHelper.userErrorInfo("鎻愮幇:鏀粯瀹濇彁鐜板紓甯革細" + response + ",鎻愮幇淇℃伅" + GsonUtil.toJson(extract)); } @@ -519,8 +546,31 @@ } catch (Exception e) { e.printStackTrace(); } + List<PayInfo> payInfoList = payInfoMapper.getListbyExtractId(extract.getId()); + String alipayNo = ""; + if (payInfoList != null && payInfoList.size() > 0) + alipayNo = payInfoList.get(0).getOrderId(); + + UserMoneyDetail detailNew = null; + try { + detailNew = UserMoneyDetailFactory.createExtract(updateExtract, alipayNo); + } catch (UserMoneyDetailException e) { + e.printStackTrace(); + } + + // 澶栨樉璐︽埛鏄庣粏 + 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()); + if (detailNew != null) + detail.setDescInfo(detailNew.getDescInfo()); + userMoneyDetailMapper.updateByPrimaryKeySelective(detail); + } // 鏂扮増閫氱煡 - userMoneyMsgNotificationService.extractSuccess(extract); + userMoneyMsgNotificationService.extractSuccess(extract, alipayNo); } /** @@ -531,7 +581,7 @@ return extractMapper.selectByPrimaryKey(id); } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void checkExtract(Long uid) throws ExtractException { BigDecimal compensateMoney = extractMapper.computeCompensateByUid(uid); @@ -683,16 +733,6 @@ // 鏇存柊鎻愮幇璁板綍瀹℃牳琛� 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); } } @@ -873,10 +913,6 @@ LogHelper.errorDetailInfo(e); } - // 4銆佸彂閫佹秷鎭�氱煡 - String desc = "涓轰繚闅滀綘鐨勮处鎴蜂綑棰濆畨鍏紝鑷姩鎻愮幇閲戦灏嗕笉浼氶珮浜�5鍏�"; - String beizu = "璐︽埛涓墿浣欎綑棰濊鍦ㄦ湰App鍐呭畬鎴愭彁鐜�"; - userMoneyMsgNotificationService.extractAuto(extractRecord, "鏈鍙�-鎻愮幇涓�", desc, beizu); } private boolean parseSendResult(String result) { @@ -1077,6 +1113,111 @@ return listOpendIDs; } + @Override + public List<UserInfo> preAutoUserTo1212() throws Exception { + int page = 0; + int pageSize = 100; + int maxSize = 300; + Date nowDate = new Date(); + // 鏉′欢3锛氳窛绂讳笂涓�娆℃垚鍔熼鍙栧井淇$孩鍖呭凡缁忚秴杩囦簡30澶╂椂闂达紝鍙湪绗�31澶╁啀娆′笅鍙戯紱 + String receivedDate = DateUtil.reduceDayTostring(30, nowDate); + // 鏉′欢4锛氳窛绂讳笂涓�娆℃湭鎴愬姛棰嗗彇寰俊绾㈠寘宸茬粡瓒呰繃浜�15澶╂椂闂达紝鍙湪绗�16澶╁啀娆′笅鍙戯紱 + String refundDate = DateUtil.reduceDayTostring(15, nowDate); + // 浣欓鏈�浣庨檺鍒� + List<UserInfo> list = new ArrayList<UserInfo>(); + while (true) { + // 鏌ヨ婊¤冻鏉′欢 1銆�2 鐨剈id + List<UserInfo> listUser = userInfoService.getAutoExtractUserTo1212(page * pageSize, pageSize); + if (listUser == null || listUser.isEmpty()) + break; + + List<Long> listId = new ArrayList<Long>(); + for (UserInfo userInfo : listUser) { + listId.add(userInfo.getId()); + } + + // 鏌ヨ璁板綍鏄惁婊¤冻 + List<Long> listValid = extractWeiXinRecordService.getValidUsers(listId, receivedDate, refundDate); + if (listValid == null || listValid.isEmpty()) { + page++; + continue; + } + + for (Long uid : listValid) { + if (list.size() >= maxSize) + break; + for (UserInfo userInfo : listUser) { + if (list.size() >= maxSize) + break; + + if (userInfo.getId().longValue() == uid.longValue()) { + list.add(userInfo); + break; + } + } + } + + if (list.size() >= maxSize) + break; + + page++; + } + return list; + } + + @Override + public List<String> getAutoExtractOpenIdsTo1212() throws Exception { + int page = 0; + int pageSize = 100; + int maxSize = 301; // appId + 瀹為檯openid300涓� + Date nowDate = new Date(); + // 鏉′欢3锛氳窛绂讳笂涓�娆℃垚鍔熼鍙栧井淇$孩鍖呭凡缁忚秴杩囦簡30澶╂椂闂达紝鍙湪绗�31澶╁啀娆′笅鍙戯紱 + String receivedDate = DateUtil.reduceDayTostring(30, nowDate); + // 鏉′欢4锛氳窛绂讳笂涓�娆℃湭鎴愬姛棰嗗彇寰俊绾㈠寘宸茬粡瓒呰繃浜�15澶╂椂闂达紝鍙湪绗�16澶╁啀娆′笅鍙戯紱 + String refundDate = DateUtil.reduceDayTostring(15, nowDate); + + // 鎻愮幇閲戦 + BigDecimal money = BigDecimal.valueOf(1); + + List<String> listOpendIDs = new ArrayList<String>(); + // 棣栬appID + listOpendIDs.add(Constant.getWXAccount(null, null).getAppId()); + + while (true) { + // 鏌ヨ婊¤冻鏉′欢 1銆�2 鐨剈id + List<UserInfo> listUser = userInfoService.getAutoExtractUserTo1212(page * pageSize, pageSize); + if (listUser == null || listUser.isEmpty()) + break; + + List<Long> listId = new ArrayList<Long>(); + for (UserInfo userInfo : listUser) { + listId.add(userInfo.getId()); + } + + // 鏌ヨ璁板綍鏄惁婊¤冻 + List<Long> listValid = extractWeiXinRecordService.getValidUsers(listId, receivedDate, refundDate); + if (listValid == null || listValid.isEmpty()) { + page++; + continue; + } + + for (Long uid : listValid) { + UserInfo userInfo = subHongBaoByUid(uid, money, money); + if (userInfo != null) { + listOpendIDs.add(userInfo.getWxOpenId()); + if (listOpendIDs.size() >= maxSize) + break; + } + } + + if (listOpendIDs.size() >= maxSize) + break; + + page++; + } + return listOpendIDs; + } + @Transactional(rollbackFor = Exception.class) private UserInfo subHongBaoByUid(Long uid, BigDecimal money, BigDecimal minSurplus) { UserInfo userInfo = userInfoMapper.selectByPrimaryKeyForUpdate(uid); @@ -1109,11 +1250,6 @@ // 璧勯噾璁$畻 userMoneyService.subUserMoney(userInfo.getId(), money, detail); - - // 4銆佸彂閫佹秷鎭�氱煡 - String desc = "涓轰繚闅滀綘鐨勮处鎴蜂綑棰濆畨鍏紝鑷姩鎻愮幇閲戦灏嗕笉浼氶珮浜�5鍏�"; - String beizu = "璐︽埛涓墿浣欎綑棰濊鍦ㄦ湰App鍐呭畬鎴愭彁鐜�"; - userMoneyMsgNotificationService.extractAuto(extractRecord, "鏈鍙�-鎻愮幇涓�", desc, beizu); // 婊¤冻鏉′欢杩斿洖淇℃伅 return userInfo; @@ -1200,8 +1336,6 @@ extractWeiXinRecordService.updateByPrimaryKeySelective(updeteRecord); if (ExtractWeiXinRecord.RECEIVED.equals(status)) { - // 鍙戦�佹秷鎭�氱煡 - userMoneyMsgNotificationService.extractAuto(record, "宸查鍙�-宸叉彁鐜�", null, null); } else if (ExtractWeiXinRecord.REFUND.equals(status)) { // 璧勯噾鏄庣粏 UserMoneyDetail detail = new UserMoneyDetail(); @@ -1213,12 +1347,8 @@ 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); } } -- Gitblit v1.8.0