|
|
@ -1,13 +1,8 @@
|
|
|
|
package au.com.royalpay.payment.manage.task;
|
|
|
|
package au.com.royalpay.payment.manage.task;
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.channels.rpay.runtime.RpayApi;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import au.com.royalpay.payment.manage.merchants.core.ClientModifySupport;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.merchants.entity.impls.SwitchPermissionModify;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
|
|
|
|
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;
|
|
|
@ -23,12 +18,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
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 org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
|
@ -47,17 +39,9 @@ public class PostponeClientTask {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ClientManager clientManager;
|
|
|
|
private ClientManager clientManager;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ClientAccountMapper clientAccountMapper;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private ManagerMapper managerMapper;
|
|
|
|
private ManagerMapper managerMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private SynchronizedScheduler synchronizedScheduler;
|
|
|
|
private SynchronizedScheduler synchronizedScheduler;
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private ClientModifySupport clientModifySupport;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private RpayApi rpayApi;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private ClientMapper clientMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 30 8 * * ?")
|
|
|
|
@Scheduled(cron = "0 30 8 * * ?")
|
|
|
|
public void postponeClient() {
|
|
|
|
public void postponeClient() {
|
|
|
@ -67,78 +51,25 @@ public class PostponeClientTask {
|
|
|
|
Date yearTomorrow = DateUtils.addYears(tomorrow, 1);
|
|
|
|
Date yearTomorrow = DateUtils.addYears(tomorrow, 1);
|
|
|
|
String expireDate = DateFormatUtils.format(yearTomorrow, "yyyy-MM-dd");
|
|
|
|
String expireDate = DateFormatUtils.format(yearTomorrow, "yyyy-MM-dd");
|
|
|
|
List<JSONObject> expiryClient = clientRateMapper.getAllExpiry(now);
|
|
|
|
List<JSONObject> expiryClient = clientRateMapper.getAllExpiry(now);
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (CollectionUtils.isEmpty(expiryClient)) {
|
|
|
|
if (CollectionUtils.isEmpty(expiryClient)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<Integer, JSONObject> expiryClients = new HashMap<>();
|
|
|
|
for (JSONObject client : expiryClient) {
|
|
|
|
expiryClient.forEach(p -> {
|
|
|
|
try {
|
|
|
|
expiryClients.put(p.getInteger("client_id"), p);
|
|
|
|
clientManager.postponeClientRate(now, yearTomorrow, expireDate, client);
|
|
|
|
});
|
|
|
|
sb.append(client.getString("client_moniker"));
|
|
|
|
expiryClients.values().forEach(p -> {
|
|
|
|
sb.append("、");
|
|
|
|
int client_id = p.getIntValue("client_id");
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(client_id);
|
|
|
|
continue;
|
|
|
|
List<JSONObject> clientRates = clientRateMapper.maxChannelExpiryTime(client_id, null);
|
|
|
|
|
|
|
|
JSONObject wechatRate = clientRateMapper.latestChannelCleanDays("Wechat", p.getIntValue("client_id"));
|
|
|
|
|
|
|
|
int cleanDays = 1;
|
|
|
|
|
|
|
|
if (wechatRate.getInteger("clean_days") != null) {
|
|
|
|
|
|
|
|
cleanDays = wechatRate.getIntValue("clean_days");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cleanDays = wechatRate.getIntValue("c_clean_days");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int finalCleanDays = cleanDays;
|
|
|
|
|
|
|
|
clientRates.forEach(o -> {
|
|
|
|
|
|
|
|
JSONObject record = clientRateMapper.latestExpiryConfig(client_id, o.getString("rate_name"));
|
|
|
|
|
|
|
|
record.remove("client_rate_id");
|
|
|
|
|
|
|
|
record.put("active_time", now);
|
|
|
|
|
|
|
|
record.put("manager_id", 0);
|
|
|
|
|
|
|
|
record.put("expiry_time", yearTomorrow);
|
|
|
|
|
|
|
|
record.put("create_time", now);
|
|
|
|
|
|
|
|
record.put("update_time", now);
|
|
|
|
|
|
|
|
record.put("clean_days", finalCleanDays);
|
|
|
|
|
|
|
|
record.put("manager_name", "System");
|
|
|
|
|
|
|
|
record.put("remark", "费率到期系统自动延期1年");
|
|
|
|
|
|
|
|
clientRateMapper.saveRate(record);
|
|
|
|
|
|
|
|
if ("Rpay".equals(o.getString("rate_name"))) {
|
|
|
|
|
|
|
|
rpayApi.modifySurchargeConfig(clientMapper.findClient(client_id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
clientModifySupport.processClientConfigModify(new SwitchPermissionModify(null, p.getString("client_moniker"), "tax_in_surcharge", false));
|
|
|
|
|
|
|
|
adminAccounts.forEach(o -> {
|
|
|
|
|
|
|
|
sendClientPostponeNotify(o, expireDate);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
sendComplianceNotify(expiryClients, expireDate);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void sendClientPostponeNotify(JSONObject account, String newExpireDate) {
|
|
|
|
|
|
|
|
JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(account.getString("wechat_openid"))) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(account.getString("wechat_openid"));
|
|
|
|
sb.deleteCharAt(sb.length() - 1);
|
|
|
|
if (api != null) {
|
|
|
|
sendComplianceNotify(sb, expireDate);
|
|
|
|
String templateId = api.getTemplateId("client-postpone");
|
|
|
|
});
|
|
|
|
if (templateId != null) {
|
|
|
|
|
|
|
|
TemplateMessage notice = initClientMessage(client, newExpireDate, account.getString("wechat_openid"), templateId);
|
|
|
|
|
|
|
|
api.sendTemplateMessage(notice);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
logger.error("Sending Notify failure", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendComplianceNotify(Map<Integer, JSONObject> clients, String newExpireDate) {
|
|
|
|
private void sendComplianceNotify(StringBuilder sb, String newExpireDate) {
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
|
|
|
|
clients.values().forEach(p -> {
|
|
|
|
|
|
|
|
sb.append(p.getString("client_moniker"));
|
|
|
|
|
|
|
|
sb.append("、");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
sb.deleteCharAt(sb.length() - 1);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -147,16 +78,6 @@ public class PostponeClientTask {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TemplateMessage initClientMessage(JSONObject client, String newExpiryDate, String wechatOpenid, String templateId) {
|
|
|
|
|
|
|
|
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, null);
|
|
|
|
|
|
|
|
notice.put("first", "您好,您的合同费率已到期,根据合同协议系统已自动为您延期1年。", "#ff0000");
|
|
|
|
|
|
|
|
notice.put("keyword1", client.getString("short_name") + "(" + client.getString("client_moniker") + ")", "#ff0000");
|
|
|
|
|
|
|
|
notice.put("keyword2", newExpiryDate, "#0000ff");
|
|
|
|
|
|
|
|
notice.put("remark", "如有疑问请联系RoyalPay", "#000000");
|
|
|
|
|
|
|
|
return notice;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TemplateMessage initComplianceMessage(String clients, String newExpiryDate, String wechatOpenid, String templateId) {
|
|
|
|
private TemplateMessage initComplianceMessage(String clients, String newExpiryDate, String wechatOpenid, String templateId) {
|
|
|
|
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, null);
|
|
|
|
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, null);
|
|
|
|
notice.put("first", "以下商户据合同费率已经自动延期1年", "#ff0000");
|
|
|
|
notice.put("first", "以下商户据合同费率已经自动延期1年", "#ff0000");
|
|
|
@ -165,5 +86,4 @@ public class PostponeClientTask {
|
|
|
|
notice.put("remark", " ", "#000000");
|
|
|
|
notice.put("remark", " ", "#000000");
|
|
|
|
return notice;
|
|
|
|
return notice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|