自动延期调整

master
yixian 5 years ago
parent b067ee39a9
commit 846414fca7

@ -52,7 +52,7 @@ public interface ClientRateMapper {
List<JSONObject> getAllClientRateExpiryMerchants(); List<JSONObject> 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); JSONObject latestChannelCleanDays(@Param("rate_name") String rate_name, @Param("client_id") int client_id);

@ -496,7 +496,7 @@ public interface ClientManager {
* *
* @param clientId * @param clientId
*/ */
boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate); boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate, List<String> channels);
JSONObject comListPartnerSelection(JSONObject manager, PartnerQuery query); JSONObject comListPartnerSelection(JSONObject manager, PartnerQuery query);

@ -6418,9 +6418,11 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Override @Override
@Transactional @Transactional
public boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate) { public boolean postponeClientRate(int clientId, String clientMoniker, String nextYearExipryDate, List<String> channels) {
try { try {
clientRateMapper.postponeMerchantRateByClientId(clientId); for (String channel : channels) {
clientRateMapper.postponeMerchantRateByClientId(clientId, channel);
}
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(clientId); List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(clientId);
adminAccounts.forEach(o -> { adminAccounts.forEach(o -> {
sendClientPostponeNotify(o, nextYearExipryDate); sendClientPostponeNotify(o, nextYearExipryDate);

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.task; 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.ClientRateMapper;
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; 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.MpWechatApiProvider;
import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage; import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage;
import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler; import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -19,10 +18,9 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* Created by wangning on 2018/1/2. * Created by wangning on 2018/1/2.
@ -42,6 +40,8 @@ public class PostponeClientTask {
private ManagerMapper managerMapper; private ManagerMapper managerMapper;
@Resource @Resource
private SynchronizedScheduler synchronizedScheduler; private SynchronizedScheduler synchronizedScheduler;
@Resource
private PaymentApi paymentApi;
@Scheduled(cron = "0 30 8 * * ?") @Scheduled(cron = "0 30 8 * * ?")
public void postponeClient() { public void postponeClient() {
@ -65,7 +65,7 @@ public class PostponeClientTask {
} }
} }
sb.deleteCharAt(sb.length() - 1); sb.deleteCharAt(sb.length() - 1);
sendComplianceNotify(sb, expireDate); sendComplianceNotify(sb.toString(), expireDate);
}); });
} }
@ -73,24 +73,38 @@ public class PostponeClientTask {
private void postponeMerchantRate() { private void postponeMerchantRate() {
synchronizedScheduler.executeProcess("manage_task:postponeMerchantRate", 120_000, () -> { synchronizedScheduler.executeProcess("manage_task:postponeMerchantRate", 120_000, () -> {
String nextYearExipryDate = DateFormatUtils.format(DateUtils.addYears(new Date(), 1), "yyyy-MM-dd"); String nextYearExipryDate = DateFormatUtils.format(DateUtils.addYears(new Date(), 1), "yyyy-MM-dd");
List<JSONObject> expiryRateMerchants = clientRateMapper.getAllClientRateExpiryMerchants(); List<JSONObject> expiryRateMerchantsChannels = clientRateMapper.getAllClientRateExpiryMerchants();
StringBuilder merchantStrBuilder = new StringBuilder(); Map<String, JSONObject> expiryRateMerchants = expiryRateMerchantsChannels.stream().filter(m -> isActiveChannel(m.getString("rate_name")))
expiryRateMerchants.forEach(merchant -> { .collect(HashMap::new, this::addMerchant, (map1, map2) -> map2.forEach((moniker, mch) -> addMerchant(map1, mch)));
if (clientManager.postponeClientRate(merchant.getIntValue("client_id"), merchant.getString("client_moniker"),nextYearExipryDate)) { sendComplianceNotify(expiryRateMerchants.values().stream()
merchantStrBuilder.append(merchant.getString("client_moniker")).append("、"); .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()
merchantStrBuilder.deleteCharAt(merchantStrBuilder.length() - 1); .collect(Collectors.joining("、")), nextYearExipryDate);
sendComplianceNotify(merchantStrBuilder, nextYearExipryDate);
}); });
} }
private void addMerchant(Map<String, JSONObject> 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<String> 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<String> compliance = managerMapper.listOpenIdsOfCompliances(); List<String> compliance = managerMapper.listOpenIdsOfCompliances();
compliance.forEach(p -> { compliance.forEach(p -> {
MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(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); api.sendTemplateMessage(notice);
}); });
} }

@ -121,40 +121,34 @@
</select> </select>
<select id="getAllClientRateExpiryMerchants" resultType="com.alibaba.fastjson.JSONObject"> <select id="getAllClientRateExpiryMerchants" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT DISTINCT select c.client_id,client_moniker,r.rate_name,max(r.expiry_time) max_expire from sys_clients c
c.client_moniker, inner join sys_client_rates r on r.client_id=c.client_id
c.client_id where
FROM sys_clients c (
LEFT JOIN sys_client_rates r c.approve_result = 1
ON r.client_id = c.client_id OR (
WHERE c.skip_clearing = 0 c.approve_result = 2
AND (c.approve_result = 1 AND ( c.source = 1 OR c.source = 2 )))
OR (c.approve_result = 2 and c.is_valid = 1
AND (c.source = 1 group by c.client_id,client_moniker,rate_name
OR c.source = 2))) HAVING max_expire<=curdate()
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 r.expiry_time <= CURRENT_DATE()
OR r.client_rate_id IS NULL
)
]]> ]]>
</select> </select>
<insert id="postponeMerchantRateByClientId" parameterType="int"> <insert id="postponeMerchantRateByClientId" parameterType="int">
<![CDATA[
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) 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(), 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,'费率自动延期一年' CONCAT('System-', CURRENT_DATE()),r.clean_days,'费率自动延期一年'
FROM sys_clients c FROM (select rr.* from sys_client_rates rr
LEFT JOIN sys_client_rates r ON r.client_id = c.client_id WHERE rr.client_id = #{clientId}
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 rr.rate_name = #{channel}
AND c.is_valid = 1 AND (r.expiry_time = (SELECT MAX(expiry_time)FROM sys_client_rates r3 order by rr.expiry_time desc limit 1) r
WHERE r3.client_id = c.client_id where r.expiry_time< current_date()
AND r3.rate_name = r.rate_name)
AND CURRENT_DATE() >= r.expiry_time
OR r.client_rate_id IS NULL) ]]>
</insert> </insert>
<select id="latestConfig" resultType="com.alibaba.fastjson.JSONObject"> <select id="latestConfig" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM SELECT * FROM

Loading…
Cancel
Save