From 58fb928ef2d338233ccda9d0066bcebc4f2e0c45 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 26 Sep 2018 17:44:08 +0800 Subject: [PATCH] update --- .../manage/task/PostponeClientTask.java | 97 ++++++++++--------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java b/src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java index 9b76c96d6..22dea8cc4 100644 --- a/src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java +++ b/src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java @@ -22,13 +22,13 @@ import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.util.Date; -import java.util.HashMap; +import java.util.LinkedList; import java.util.List; -import java.util.Map; import javax.annotation.Resource; @@ -67,51 +67,60 @@ public class PostponeClientTask { Date yearTomorrow = DateUtils.addYears(tomorrow, 1); String expireDate = DateFormatUtils.format(yearTomorrow, "yyyy-MM-dd"); List expiryClient = clientRateMapper.getAllExpiry(now); - + StringBuilder sb = new StringBuilder(); + List successClients = new LinkedList<>(); if (CollectionUtils.isEmpty(expiryClient)) { return; } - Map expiryClients = new HashMap<>(); - expiryClient.forEach(p -> { - expiryClients.put(p.getInteger("client_id"), p); - }); - expiryClients.values().forEach(p -> { - int client_id = p.getIntValue("client_id"); - List adminAccounts = clientAccountMapper.listAdminAccounts(client_id); - List clientRates = clientRateMapper.maxChannelExpiryTime(client_id, null); - JSONObject wechatRate = clientRateMapper.latestChannelCleanDays("Wechat", p.getIntValue("client_id")); - int cleanDays = 1; - if (wechatRate.getInteger("clean_days") != null) { - cleanDays = wechatRate.getIntValue("clean_days"); - } else { - cleanDays = wechatRate.getIntValue("c_clean_days"); + for (JSONObject p : expiryClient) { + try { + modifyRate(now, yearTomorrow, expireDate, p, sb); + } catch (Exception ignore) { + continue; } - int finalCleanDays = cleanDays; - clientRates.forEach(o -> { - JSONObject record = clientRateMapper.latestExpiryConfig(client_id, o.getString("rate_name")); - record.remove("client_rate_id"); - record.put("active_time", now); - record.put("manager_id", 0); - record.put("expiry_time", yearTomorrow); - record.put("create_time", now); - record.put("update_time", now); - record.put("clean_days", finalCleanDays); - record.put("manager_name", "System"); - record.put("remark", "费率到期系统自动延期1年"); - clientRateMapper.saveRate(record); - if ("Rpay".equals(o.getString("rate_name"))) { - rpayApi.modifySurchargeConfig(clientMapper.findClient(client_id)); - } - }); - clientModifySupport.processClientConfigModify(new SwitchPermissionModify(null, p.getString("client_moniker"), "tax_in_surcharge", false)); - adminAccounts.forEach(o -> { - sendClientPostponeNotify(o, expireDate); - }); - }); - sendComplianceNotify(expiryClients, expireDate); + } + sb.deleteCharAt(sb.length() - 1); + sendComplianceNotify(sb, expireDate); }); } + @Transactional + public void modifyRate(Date now, Date yearTomorrow, String expireDate, JSONObject p, StringBuilder sb) { + int client_id = p.getIntValue("client_id"); + List adminAccounts = clientAccountMapper.listAdminAccounts(client_id); + List clientRates = clientRateMapper.maxChannelExpiryTime(client_id, null); + JSONObject wechatRate = clientRateMapper.latestChannelCleanDays("Wechat", p.getIntValue("client_id")); + int cleanDays = 1; + if (wechatRate.getInteger("clean_days") != null) { + cleanDays = wechatRate.getIntValue("clean_days"); + } else { + cleanDays = wechatRate.getIntValue("c_clean_days"); + } + int finalCleanDays = cleanDays; + clientRates.forEach(o -> { + JSONObject record = clientRateMapper.latestExpiryConfig(client_id, o.getString("rate_name")); + record.remove("client_rate_id"); + record.put("active_time", now); + record.put("manager_id", 0); + record.put("expiry_time", yearTomorrow); + record.put("create_time", now); + record.put("update_time", now); + record.put("clean_days", finalCleanDays); + record.put("manager_name", "System"); + record.put("remark", "费率到期系统自动延期1年"); + clientRateMapper.saveRate(record); + if ("Rpay".equals(o.getString("rate_name"))) { + rpayApi.modifySurchargeConfig(clientMapper.findClient(client_id)); + } + }); + clientModifySupport.processClientConfigModify(new SwitchPermissionModify(null, p.getString("client_moniker"), "tax_in_surcharge", false)); + adminAccounts.forEach(o -> { + sendClientPostponeNotify(o, expireDate); + }); + sb.append(p.getString("client_moniker")); + sb.append("、"); + } + private void sendClientPostponeNotify(JSONObject account, String newExpireDate) { JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id")); @@ -132,13 +141,7 @@ public class PostponeClientTask { } } - private void sendComplianceNotify(Map clients, String newExpireDate) { - StringBuffer sb = new StringBuffer(); - clients.values().forEach(p -> { - sb.append(p.getString("client_moniker")); - sb.append("、"); - }); - sb.deleteCharAt(sb.length() - 1); + private void sendComplianceNotify(StringBuilder sb, String newExpireDate) { List compliance = managerMapper.listOpenIdsOfCompliances(); compliance.forEach(p -> { MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(p);