Merge branch 'hotfix-autoexpire-surcharge' into develop

master
yixian 4 years ago
commit 906f53fa86

@ -52,7 +52,7 @@ public interface ClientRateMapper {
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);

@ -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<String> channels);
JSONObject comListPartnerSelection(JSONObject manager, PartnerQuery query);

@ -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<String> channels) {
try {
clientRateMapper.postponeMerchantRateByClientId(clientId);
for (String channel : channels) {
clientRateMapper.postponeMerchantRateByClientId(clientId, channel);
}
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(clientId);
adminAccounts.forEach(o -> {
sendClientPostponeNotify(o, nextYearExipryDate);

@ -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);
});
}

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

Loading…
Cancel
Save