parent
518b0639b4
commit
0d7d2ade26
@ -0,0 +1,117 @@
|
||||
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.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 au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Created by wangning on 2018/1/2.
|
||||
*/
|
||||
@Component
|
||||
//@ConditionalOnProperty(value = "app.run-tasks", havingValue = "true")
|
||||
public class PostponeClientTask {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(PostponeClientTask.class);
|
||||
@Resource
|
||||
private ClientRateMapper clientRateMapper;
|
||||
@Resource
|
||||
private MpWechatApiProvider mpWechatApiProvider;
|
||||
@Resource
|
||||
private ClientManager clientManager;
|
||||
@Resource
|
||||
private ClientAccountMapper clientAccountMapper;
|
||||
|
||||
// @Scheduled(cron = "0 30 8 * * ?")
|
||||
public void checkGreenChannel() {
|
||||
Date now = new Date();
|
||||
Date tomorrow = DateUtils.addDays(now, 1);
|
||||
List<JSONObject> expiryClient = clientRateMapper.getAllExpiry(now);
|
||||
|
||||
Map<Integer, JSONObject> expiryClients = new HashMap<>();
|
||||
expiryClient.forEach(p -> {
|
||||
expiryClients.put(p.getInteger("client_id"), p);
|
||||
List<JSONObject> clientRates = clientRateMapper.maxChannelExpiryTime(p.getIntValue("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 -> {
|
||||
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("create_time", now);
|
||||
o.put("update_time", now);
|
||||
o.put("clean_days", finalCleanDays);
|
||||
o.put("manager_name", "System");
|
||||
o.put("remark", "费率到期系统自动延期1年");
|
||||
clientRateMapper.saveRate(o);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
expiryClients.keySet().forEach(p -> {
|
||||
List<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(p);
|
||||
adminAccounts.forEach(o -> {
|
||||
sendPostponeNotify(o);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void sendPostponeNotify(JSONObject account) {
|
||||
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");
|
||||
if (templateId != null) {
|
||||
// TemplateMessage notice = initMessage(event, operator.getString("display_name"), client,
|
||||
// event.getRefundOrder(), templateId, wechatOpenid);
|
||||
// api.sendTemplateMessage(notice);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Sending Notify failure", e);
|
||||
}
|
||||
}
|
||||
|
||||
private TemplateMessage initMessage(NewRefundReviewEvent newRefundReviewEvent, String operatorName, JSONObject client, JSONObject review, String templateId,
|
||||
String wechatOpenid) {
|
||||
String uri = "/api/payment/v1.0/refund/review/" + review.getString("review_id");
|
||||
String loginUrl = PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat") + "?target=" + uri;
|
||||
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, loginUrl);
|
||||
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");
|
||||
return notice;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue