|
|
|
@ -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<JSONObject> 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<JSONObject> expiryRateMerchantsChannels = clientRateMapper.getAllClientRateExpiryMerchants();
|
|
|
|
|
Map<String, JSONObject> 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<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();
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|