|
|
|
@ -2,18 +2,21 @@ package au.com.royalpay.payment.manage.task;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
|
|
|
|
|
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;
|
|
|
|
|
import au.com.royalpay.payment.manage.tradelog.refund.events.NewRefundReviewEvent;
|
|
|
|
|
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 com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -38,16 +41,26 @@ public class PostponeClientTask {
|
|
|
|
|
private ClientManager clientManager;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientAccountMapper clientAccountMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ManagerMapper managerMapper;
|
|
|
|
|
|
|
|
|
|
// @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 -> {
|
|
|
|
|
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(p.getIntValue("client_id"));
|
|
|
|
|
List<JSONObject> clientRates = clientRateMapper.maxChannelExpiryTime(p.getIntValue("client_id"), null);
|
|
|
|
|
JSONObject wechatRate = clientRateMapper.latestChannelCleanDays("Wechat", p.getIntValue("client_id"));
|
|
|
|
|
int cleanDays = 1;
|
|
|
|
@ -61,7 +74,7 @@ public class PostponeClientTask {
|
|
|
|
|
o.remove("client_rate_id");
|
|
|
|
|
o.put("active_time", tomorrow);
|
|
|
|
|
o.put("manager_id", 0);
|
|
|
|
|
o.put("expiry_time", DateUtils.addYears(tomorrow, 1));
|
|
|
|
|
o.put("expiry_time", yearTomorrow);
|
|
|
|
|
o.put("create_time", now);
|
|
|
|
|
o.put("update_time", now);
|
|
|
|
|
o.put("clean_days", finalCleanDays);
|
|
|
|
@ -70,28 +83,23 @@ public class PostponeClientTask {
|
|
|
|
|
clientRateMapper.saveRate(o);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expiryClients.keySet().forEach(p -> {
|
|
|
|
|
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(p);
|
|
|
|
|
adminAccounts.forEach(o -> {
|
|
|
|
|
sendClientPostponeNotify(o);
|
|
|
|
|
sendClientPostponeNotify(o, expireDate);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sendComplianceNotify(expiryClients, expireDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendClientPostponeNotify(JSONObject account) {
|
|
|
|
|
private void sendClientPostponeNotify(JSONObject account,String newExpireDate) {
|
|
|
|
|
JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id"));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(account.getString("wechat_openid"));
|
|
|
|
|
if (api != null) {
|
|
|
|
|
String templateId = api.getTemplateId("refund-audit-notice");
|
|
|
|
|
String templateId = api.getTemplateId("client-postpone");
|
|
|
|
|
if (templateId != null) {
|
|
|
|
|
// TemplateMessage notice = initMessage(event, operator.getString("display_name"), client,
|
|
|
|
|
// event.getRefundOrder(), templateId, wechatOpenid);
|
|
|
|
|
// api.sendTemplateMessage(notice);
|
|
|
|
|
TemplateMessage notice = initClientMessage(client,newExpireDate,account.getString("wechat_openid"),templateId);
|
|
|
|
|
api.sendTemplateMessage(notice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -99,21 +107,37 @@ public class PostponeClientTask {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendComplianceNotify(Map<Integer,JSONObject> clients){
|
|
|
|
|
clients.values().forEach(p->{
|
|
|
|
|
private void sendComplianceNotify(Map<Integer, JSONObject> clients, 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();
|
|
|
|
|
compliance.forEach(p -> {
|
|
|
|
|
MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(p);
|
|
|
|
|
TemplateMessage notice = initComplianceMessage(sb.toString(), newExpireDate, p, api.getTemplateId("client-postpone"));
|
|
|
|
|
api.sendTemplateMessage(notice);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TemplateMessage initMessage(NewRefundReviewEvent newRefundReviewEvent, String operatorName, JSONObject client, JSONObject review, String templateId,
|
|
|
|
|
String wechatOpenid) {
|
|
|
|
|
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, "asd");
|
|
|
|
|
notice.put("first", operatorName + "提交了订单的退款申请,请审核", "#ff0000");
|
|
|
|
|
notice.put("keyword1", review.getString("currency") + newRefundReviewEvent.getRefundOrder().getDoubleValue("amount"), "#ff0000");
|
|
|
|
|
notice.put("keyword2", operatorName, "#0000ff");
|
|
|
|
|
notice.put("keyword3", client.getString("short_name") + "(" + client.getString("client_moniker") + ")", "#0000ff");
|
|
|
|
|
notice.put("keyword4", review.getString("remark") == null ? "无备注" : review.getString("remark"), "#0000FF");
|
|
|
|
|
notice.put("remark", "点击处理", "#000000");
|
|
|
|
|
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) {
|
|
|
|
|
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, null);
|
|
|
|
|
notice.put("first", "以下商户据合同费率已经自动延期1年", "#ff0000");
|
|
|
|
|
notice.put("keyword1", clients, "#ff0000");
|
|
|
|
|
notice.put("keyword2", newExpiryDate, "#0000ff");
|
|
|
|
|
notice.put("remark", " ", "#000000");
|
|
|
|
|
return notice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|