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 b9e5ed634..3f245f99a 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 @@ -46,6 +46,10 @@ public interface ClientRateMapper { List getAllExpiry(@Param("expiry_date")Date expiry_date); + List getAllClientRateExpiryMerchants(); + + void postponeMerchantRateByClientId(int clientId); + JSONObject latestChannelCleanDays(@Param("rate_name")String rate_name, @Param("client_id")int client_id); JSONObject latestExpiryConfig(@Param("client_id")int client_id,@Param("rate_name") String rate_name); 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 8bcca2a11..9589510d6 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 @@ -342,4 +342,11 @@ public interface ClientManager { void updateAllPartnerPassword(String clientMoniker, List emails); void postponeClientRate(Date now, Date yearTomorrow, String expireDate, JSONObject client); + + /** + * 根据商户之前的费率自动延期一年 + * + * @param clientId + */ + boolean postponeClientRate(int clientId, String clientMoniker,String nextYearExipryDate); } 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 f928885fd..fd3cd717d 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 @@ -4029,6 +4029,23 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid }); } + @Override + @Transactional + public boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate) { + try { + clientRateMapper.postponeMerchantRateByClientId(clientId); + clientModifySupport.processClientConfigModify(new SwitchPermissionModify(null, clientMoniker, "tax_in_surcharge", false)); + List adminAccounts = clientAccountMapper.listAdminAccounts(clientId); + adminAccounts.forEach(o -> { + sendClientPostponeNotify(o, nextYearExipryDate); + }); + logger.error("[{}]费率自动延期成功", clientMoniker); + return true; + } catch (Exception e) { + logger.error("[{}]费率自动延期失败", clientMoniker); + return false; + } + } private TemplateMessage initClientMessage(JSONObject client, String newExpiryDate, String wechatOpenid, String templateId) { 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 c03a84d31..78bf834d3 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 @@ -69,6 +69,23 @@ public class PostponeClientTask { }); } + @Scheduled(cron = "0 30 6 * * ?") + 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); + }); + } + + private void sendComplianceNotify(StringBuilder sb, String newExpireDate) { List compliance = managerMapper.listOpenIdsOfCompliances(); compliance.forEach(p -> { @@ -76,8 +93,8 @@ public class PostponeClientTask { TemplateMessage notice = initComplianceMessage(sb.toString(), newExpireDate, p, api.getTemplateId("client-postpone")); api.sendTemplateMessage(notice); }); - } + private TemplateMessage initComplianceMessage(String clients, String newExpiryDate, String wechatOpenid, String templateId) { TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, null); notice.put("first", "以下商户据合同费率已经自动延期1年", "#ff0000"); 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 545d64bdc..27bd6b82e 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 @@ -119,6 +119,43 @@ a.expiry_time < #{expiry_date} ]]> + + + 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) +