From 0d7d2ade26efea58236d974f3de9463e788a1f4e Mon Sep 17 00:00:00 2001 From: wangning <164851225@qq.com> Date: Fri, 20 Apr 2018 17:29:08 +0800 Subject: [PATCH] update --- .../mappers/system/ClientRateMapper.java | 10 +- .../manage/task/PostponeClientTask.java | 117 ++++++++++++++++++ .../listeners/NoticeRefundReviewListener.java | 7 +- .../mappers/system/ClientRateMapper.xml | 48 +++++-- 4 files changed, 164 insertions(+), 18 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java index 0d8fc72d2..6d6bfd943 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.java @@ -37,7 +37,15 @@ public interface ClientRateMapper { @Param("expiry_time") Date expiryTime, @Param("rate_value") Double rateValue, @Param("clean_days") Integer cleanDays, @Param("rate_name") String rateName); - List minExpiryTime(@Param("client_id")int client_id,@Param("rate_name") String rate_name); + List latestConfig(@Param("client_id")int client_id,@Param("rate_name") String rate_name); + + //Task + List maxChannelExpiryTime(@Param("client_id")int client_id,@Param("rate_name")String rate_name); + + List getAllExpiry(@Param("expiry_date")Date expiry_date); + + JSONObject latestChannelCleanDays(@Param("rate_name")String rate_name, @Param("client_id")int client_id); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java b/src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java new file mode 100644 index 000000000..5c9d0861d --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/task/PostponeClientTask.java @@ -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 expiryClient = clientRateMapper.getAllExpiry(now); + + Map expiryClients = new HashMap<>(); + expiryClient.forEach(p -> { + expiryClients.put(p.getInteger("client_id"), p); + List 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 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; + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/tradelog/refund/events/listeners/NoticeRefundReviewListener.java b/src/main/java/au/com/royalpay/payment/manage/tradelog/refund/events/listeners/NoticeRefundReviewListener.java index ff771b66b..7e977e43a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/tradelog/refund/events/listeners/NoticeRefundReviewListener.java +++ b/src/main/java/au/com/royalpay/payment/manage/tradelog/refund/events/listeners/NoticeRefundReviewListener.java @@ -8,14 +8,15 @@ 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 au.com.royalpay.payment.tools.env.SysConfigManager; + import com.alibaba.fastjson.JSONObject; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.List; /** * Created by Tayl0r on 2017/7/6. @@ -84,8 +85,6 @@ public class NoticeRefundReviewListener implements ApplicationListener>>>>"+review.getString("review_id")); - logger.debug("kiratest->>>>>"+review.toJSONString()); String loginUrl = PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat") + "?target=" + uri; TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, loginUrl); notice.put("first", operatorName + "提交了订单的退款申请,请审核", "#ff0000"); @@ -99,8 +98,6 @@ public class NoticeRefundReviewListener implements ApplicationListener>>>>"+review.getString("review_id")); - logger.debug("kiratestOperator->>>>>"+review.toJSONString()); TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, uri); notice.put("first", operatorName + ",您的退款申请已提交,请等待RoyalPay审核", "#ff0000"); notice.put("keyword1", review.getString("currency") + newRefundReviewEvent.getRefundOrder().getDoubleValue("amount"), "#ff0000"); diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml index fd93ed287..f581e3fef 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/system/ClientRateMapper.xml @@ -87,20 +87,35 @@ order by update_time desc ]]> - + select cr.* ,c.client_moniker from 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) + where cr.client_id = #{client_id} + + and cr.rate_name = #{rate_name} + + group by cr.client_id, cr.rate_name + + + \ No newline at end of file