From 846414fca796fd87fcdb128e98d4b7912a050915 Mon Sep 17 00:00:00 2001 From: yixian Date: Tue, 21 Jul 2020 18:40:26 +1000 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=BB=B6=E6=9C=9F=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappers/system/ClientRateMapper.java | 2 +- .../manage/merchants/core/ClientManager.java | 2 +- .../core/impls/ClientManagerImpl.java | 6 +- .../manage/task/PostponeClientTask.java | 48 ++++++++++------ .../mappers/system/ClientRateMapper.xml | 56 +++++++++---------- 5 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java index 896a60f58..59ebd36c4 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java @@ -52,7 +52,7 @@ public interface ClientRateMapper { List getAllClientRateExpiryMerchants(); - void postponeMerchantRateByClientId(int clientId); + void postponeMerchantRateByClientId(@Param("client_id") int clientId, @Param("channel") String channel); JSONObject latestChannelCleanDays(@Param("rate_name") String rate_name, @Param("client_id") int client_id); diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java index eb4585ffb..70c2c7b6a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java @@ -496,7 +496,7 @@ public interface ClientManager { * * @param clientId */ - boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate); + boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate, List channels); JSONObject comListPartnerSelection(JSONObject manager, PartnerQuery query); diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index 2a93c40ef..fad75ed74 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -6418,9 +6418,11 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid @Override @Transactional - public boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate) { + public boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate, List channels) { try { - clientRateMapper.postponeMerchantRateByClientId(clientId); + for (String channel : channels) { + clientRateMapper.postponeMerchantRateByClientId(clientId, channel); + } List adminAccounts = clientAccountMapper.listAdminAccounts(clientId); adminAccounts.forEach(o -> { sendClientPostponeNotify(o, nextYearExipryDate); 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 78bf834d3..660d8ef75 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 @@ -1,5 +1,6 @@ package au.com.royalpay.payment.manage.task; +import au.com.royalpay.payment.core.PaymentApi; import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper; import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; import au.com.royalpay.payment.manage.merchants.core.ClientManager; @@ -7,9 +8,7 @@ import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider; import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage; import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler; - import com.alibaba.fastjson.JSONObject; - import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.slf4j.Logger; @@ -19,10 +18,9 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.util.Date; -import java.util.List; - import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; /** * Created by wangning on 2018/1/2. @@ -42,6 +40,8 @@ public class PostponeClientTask { private ManagerMapper managerMapper; @Resource private SynchronizedScheduler synchronizedScheduler; + @Resource + private PaymentApi paymentApi; @Scheduled(cron = "0 30 8 * * ?") public void postponeClient() { @@ -65,7 +65,7 @@ public class PostponeClientTask { } } sb.deleteCharAt(sb.length() - 1); - sendComplianceNotify(sb, expireDate); + sendComplianceNotify(sb.toString(), expireDate); }); } @@ -73,24 +73,38 @@ public class PostponeClientTask { private void postponeMerchantRate() { synchronizedScheduler.executeProcess("manage_task:postponeMerchantRate", 120_000, () -> { String nextYearExipryDate = DateFormatUtils.format(DateUtils.addYears(new Date(), 1), "yyyy-MM-dd"); - List expiryRateMerchants = clientRateMapper.getAllClientRateExpiryMerchants(); - StringBuilder merchantStrBuilder = new StringBuilder(); - expiryRateMerchants.forEach(merchant -> { - if (clientManager.postponeClientRate(merchant.getIntValue("client_id"), merchant.getString("client_moniker"),nextYearExipryDate)) { - merchantStrBuilder.append(merchant.getString("client_moniker")).append("、"); - } - }); - merchantStrBuilder.deleteCharAt(merchantStrBuilder.length() - 1); - sendComplianceNotify(merchantStrBuilder, nextYearExipryDate); + List expiryRateMerchantsChannels = clientRateMapper.getAllClientRateExpiryMerchants(); + Map expiryRateMerchants = expiryRateMerchantsChannels.stream().filter(m -> isActiveChannel(m.getString("rate_name"))) + .collect(HashMap::new, this::addMerchant, (map1, map2) -> map2.forEach((moniker, mch) -> addMerchant(map1, mch))); + sendComplianceNotify(expiryRateMerchants.values().stream() + .filter(m -> clientManager.postponeClientRate(m.getIntValue("client_id"), m.getString("client_moniker"), nextYearExipryDate, m.getJSONArray("channels").toJavaList(String.class))) + .map(m -> m.getString("client_moniker")) + .distinct() + .collect(Collectors.joining("、")), nextYearExipryDate); }); } + private void addMerchant(Map merchantsMap, JSONObject mch) { + if (merchantsMap.containsKey(mch.getString("client_moniker"))) { + merchantsMap.get(mch.getString("client_moniker")).getJSONArray("channels").add(mch.getString("rate_name")); + } else { + List channels = new ArrayList<>(); + channels.add(mch.getString("rate_name")); + mch.put("channels", channels); + merchantsMap.put(mch.getString("client_moniker"), mch); + } + } + + private boolean isActiveChannel(String channel) { + return "CB_BankPay".equalsIgnoreCase(channel) || paymentApi.channelsStream().anyMatch(api -> api.channel().equalsIgnoreCase(channel)); + } + - private void sendComplianceNotify(StringBuilder sb, String newExpireDate) { + private void sendComplianceNotify(String merchantsStr, String newExpireDate) { List compliance = managerMapper.listOpenIdsOfCompliances(); compliance.forEach(p -> { MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(p); - TemplateMessage notice = initComplianceMessage(sb.toString(), newExpireDate, p, api.getTemplateId("client-postpone")); + TemplateMessage notice = initComplianceMessage(merchantsStr, newExpireDate, p, api.getTemplateId("client-postpone")); api.sendTemplateMessage(notice); }); } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml index 469b5d65a..549243bbf 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml @@ -121,40 +121,34 @@ - INSERT sys_client_rates (manager_id, client_id, rate_name, rate_value, transaction_fee, active_time, expiry_time, create_time, update_time, manager_name, clean_days, remark) - SELECT CONCAT('System-', CURRENT_DATE()),r.client_id,r.rate_name,r.rate_value,r.transaction_fee,DATE_ADD(r.expiry_time, INTERVAL 1 day),DATE_ADD(r.expiry_time, INTERVAL 1 year),NOW(), NOW(), - CONCAT('System-', CURRENT_DATE()),r.clean_days,'费率自动延期一年' - FROM sys_clients c - LEFT JOIN sys_client_rates r ON r.client_id = c.client_id - WHERE c.client_id = #{clientId} AND c.skip_clearing = 0 AND (c.approve_result = 1 OR (c.approve_result = 2 AND (c.source = 1 OR c.source = 2))) - AND c.is_valid = 1 AND (r.expiry_time = (SELECT MAX(expiry_time)FROM sys_client_rates r3 - WHERE r3.client_id = c.client_id - AND r3.rate_name = r.rate_name) - AND CURRENT_DATE() >= r.expiry_time - OR r.client_rate_id IS NULL) +