|
|
|
@ -8,6 +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;
|
|
|
|
@ -44,56 +45,61 @@ public class PostponeClientTask {
|
|
|
|
|
private ClientAccountMapper clientAccountMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ManagerMapper managerMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private SynchronizedScheduler synchronizedScheduler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 30 8 * * ?")
|
|
|
|
|
@Scheduled(cron = "0 30 8 * * ?")
|
|
|
|
|
public void checkGreenChannel() {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
Date tomorrow = DateUtils.addDays(now, 1);
|
|
|
|
|
Date yearTomorrow = DateUtils.addYears(tomorrow, 1);
|
|
|
|
|
String expireDate = DateFormatUtils.format(yearTomorrow, "yyyy-MM-dd");
|
|
|
|
|
List<JSONObject> expiryClient = clientRateMapper.getAllExpiry(now);
|
|
|
|
|
|
|
|
|
|
if(CollectionUtils.isEmpty(expiryClient)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Map<Integer, JSONObject> expiryClients = new HashMap<>();
|
|
|
|
|
expiryClient.forEach(p -> {
|
|
|
|
|
expiryClients.put(p.getInteger("client_id"), p);
|
|
|
|
|
});
|
|
|
|
|
expiryClients.values().forEach(p -> {
|
|
|
|
|
int client_id = p.getIntValue("client_id");
|
|
|
|
|
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(client_id);
|
|
|
|
|
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");
|
|
|
|
|
synchronizedScheduler.executeProcess("manage_task:postPoneClient", 120_000, () -> {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
Date tomorrow = DateUtils.addDays(now, 1);
|
|
|
|
|
Date yearTomorrow = DateUtils.addYears(tomorrow, 1);
|
|
|
|
|
String expireDate = DateFormatUtils.format(yearTomorrow, "yyyy-MM-dd");
|
|
|
|
|
List<JSONObject> expiryClient = clientRateMapper.getAllExpiry(now);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(expiryClient)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
Map<Integer, JSONObject> expiryClients = new HashMap<>();
|
|
|
|
|
expiryClient.forEach(p -> {
|
|
|
|
|
expiryClients.put(p.getInteger("client_id"), p);
|
|
|
|
|
});
|
|
|
|
|
adminAccounts.forEach(o -> {
|
|
|
|
|
sendClientPostponeNotify(o, expireDate);
|
|
|
|
|
expiryClients.values().forEach(p -> {
|
|
|
|
|
int client_id = p.getIntValue("client_id");
|
|
|
|
|
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(client_id);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
adminAccounts.forEach(o -> {
|
|
|
|
|
sendClientPostponeNotify(o, expireDate);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
sendComplianceNotify(expiryClients, expireDate);
|
|
|
|
|
});
|
|
|
|
|
sendComplianceNotify(expiryClients, expireDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendClientPostponeNotify(JSONObject account,String newExpireDate) {
|
|
|
|
|
private void sendClientPostponeNotify(JSONObject account, String newExpireDate) {
|
|
|
|
|
JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id"));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -101,8 +107,8 @@ public class PostponeClientTask {
|
|
|
|
|
if (api != null) {
|
|
|
|
|
String templateId = api.getTemplateId("client-postpone");
|
|
|
|
|
if (templateId != null) {
|
|
|
|
|
TemplateMessage notice = initClientMessage(client,newExpireDate,account.getString("wechat_openid"),templateId);
|
|
|
|
|
api.sendTemplateMessage(notice);
|
|
|
|
|
TemplateMessage notice = initClientMessage(client, newExpireDate, account.getString("wechat_openid"), templateId);
|
|
|
|
|
api.sendTemplateMessage(notice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -129,7 +135,7 @@ 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("keyword1", client.getString("short_name") + "(" + client.getString("client_moniker") + ")", "#ff0000");
|
|
|
|
|
notice.put("keyword2", newExpiryDate, "#0000ff");
|
|
|
|
|
notice.put("remark", "如有疑问请联系RoyalPay", "#000000");
|
|
|
|
|
return notice;
|
|
|
|
|