client postpone

master
wangning 8 years ago
parent 3dfbfc9647
commit 8c5b02fc92

@ -30,6 +30,7 @@ public class WepayWechatApiImpl extends AbstractMpWechatClientApi implements MpW
registerTemplateId("settlement", "HqgkogBUWmfInrS5U84_9p-19LbM0apEuExHW4LF4bM"); registerTemplateId("settlement", "HqgkogBUWmfInrS5U84_9p-19LbM0apEuExHW4LF4bM");
registerTemplateId("settlement-check-code", "yaXEOjXFpuipk-DsdxYdd8PnD3bWAgDS5vTKJsrFdR4"); registerTemplateId("settlement-check-code", "yaXEOjXFpuipk-DsdxYdd8PnD3bWAgDS5vTKJsrFdR4");
registerTemplateId("daily-green-channel", "vjeNnggHnnRHvBP80lkEEtPk8ouf7JnvrQYDCyxqx4g"); registerTemplateId("daily-green-channel", "vjeNnggHnnRHvBP80lkEEtPk8ouf7JnvrQYDCyxqx4g");
registerTemplateId("client-postpone", "5eNJ5ZTKWitC1TJClb2coymtNCmOC7d86h0zCrxmGig");
} }
@Override @Override

@ -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.ClientAccountMapper;
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.merchants.core.ClientManager; 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.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;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -38,16 +41,26 @@ public class PostponeClientTask {
private ClientManager clientManager; private ClientManager clientManager;
@Resource @Resource
private ClientAccountMapper clientAccountMapper; private ClientAccountMapper clientAccountMapper;
@Resource
private ManagerMapper managerMapper;
// @Scheduled(cron = "0 30 8 * * ?") // @Scheduled(cron = "0 30 8 * * ?")
public void checkGreenChannel() { public void checkGreenChannel() {
Date now = new Date(); Date now = new Date();
Date tomorrow = DateUtils.addDays(now, 1); 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); List<JSONObject> expiryClient = clientRateMapper.getAllExpiry(now);
if(CollectionUtils.isEmpty(expiryClient)){
return;
}
Map<Integer, JSONObject> expiryClients = new HashMap<>(); Map<Integer, JSONObject> expiryClients = new HashMap<>();
expiryClient.forEach(p -> { expiryClient.forEach(p -> {
expiryClients.put(p.getInteger("client_id"), 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); List<JSONObject> clientRates = clientRateMapper.maxChannelExpiryTime(p.getIntValue("client_id"), null);
JSONObject wechatRate = clientRateMapper.latestChannelCleanDays("Wechat", p.getIntValue("client_id")); JSONObject wechatRate = clientRateMapper.latestChannelCleanDays("Wechat", p.getIntValue("client_id"));
int cleanDays = 1; int cleanDays = 1;
@ -61,7 +74,7 @@ public class PostponeClientTask {
o.remove("client_rate_id"); o.remove("client_rate_id");
o.put("active_time", tomorrow); o.put("active_time", tomorrow);
o.put("manager_id", 0); 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("create_time", now);
o.put("update_time", now); o.put("update_time", now);
o.put("clean_days", finalCleanDays); o.put("clean_days", finalCleanDays);
@ -70,28 +83,23 @@ public class PostponeClientTask {
clientRateMapper.saveRate(o); clientRateMapper.saveRate(o);
}); });
});
expiryClients.keySet().forEach(p -> {
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(p);
adminAccounts.forEach(o -> { 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")); JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id"));
try { try {
MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(account.getString("wechat_openid")); MpWechatApi api = mpWechatApiProvider.getApiFromOpenId(account.getString("wechat_openid"));
if (api != null) { if (api != null) {
String templateId = api.getTemplateId("refund-audit-notice"); String templateId = api.getTemplateId("client-postpone");
if (templateId != null) { if (templateId != null) {
// TemplateMessage notice = initMessage(event, operator.getString("display_name"), client, TemplateMessage notice = initClientMessage(client,newExpireDate,account.getString("wechat_openid"),templateId);
// event.getRefundOrder(), templateId, wechatOpenid); api.sendTemplateMessage(notice);
// api.sendTemplateMessage(notice);
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -99,21 +107,37 @@ public class PostponeClientTask {
} }
} }
private void sendComplianceNotify(Map<Integer,JSONObject> clients){ private void sendComplianceNotify(Map<Integer, JSONObject> clients, String newExpireDate) {
clients.values().forEach(p->{ 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, private TemplateMessage initClientMessage(JSONObject client, String newExpiryDate, String wechatOpenid, String templateId) {
String wechatOpenid) { TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, null);
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, "asd"); notice.put("first", "您好您的合同费率已到期根据合同协议系统已自动为您延期1年。", "#ff0000");
notice.put("first", operatorName + "提交了订单的退款申请,请审核", "#ff0000"); notice.put("keyword1", client.getString("short_name")+"("+client.getString("client_moniker")+")", "#ff0000");
notice.put("keyword1", review.getString("currency") + newRefundReviewEvent.getRefundOrder().getDoubleValue("amount"), "#ff0000"); notice.put("keyword2", newExpiryDate, "#0000ff");
notice.put("keyword2", operatorName, "#0000ff"); notice.put("remark", "如有疑问请联系RoyalPay", "#000000");
notice.put("keyword3", client.getString("short_name") + "(" + client.getString("client_moniker") + ")", "#0000ff"); return notice;
notice.put("keyword4", review.getString("remark") == null ? "无备注" : review.getString("remark"), "#0000FF"); }
notice.put("remark", "点击处理", "#000000");
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; return notice;
} }

@ -105,7 +105,8 @@
cr.client_id , cr.client_id ,
cr.active_time , cr.active_time ,
max(cr.expiry_time) expiry_time , max(cr.expiry_time) expiry_time ,
cr.rate_name cr.rate_name,
c.client_moniker
FROM FROM
sys_client_rates cr sys_client_rates cr
inner join sys_clients c on c.client_id = cr.client_id and c.is_valid = 1 and (c.approve_result = 1 or c.approve_result = 2) inner join sys_clients c on c.client_id = cr.client_id and c.is_valid = 1 and (c.approve_result = 1 or c.approve_result = 2)

@ -0,0 +1,25 @@
package au.com.royalpay.payment.manage.task;
import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@SpringBootTest
@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
@RunWith(SpringRunner.class)
public class PostponeClientTaskTest {
@Resource
private ClientRateMapper clientRateMapper;
@Resource
private PostponeClientTask postponeClientTask;
@Test
public void checkGreenChannel() {
postponeClientTask.checkGreenChannel();
}
}
Loading…
Cancel
Save