master
wangning 7 years ago
parent 518b0639b4
commit 0d7d2ade26

@ -37,7 +37,15 @@ public interface ClientRateMapper {
@Param("expiry_time") Date expiryTime, @Param("rate_value") Double rateValue, @Param("expiry_time") Date expiryTime, @Param("rate_value") Double rateValue,
@Param("clean_days") Integer cleanDays, @Param("rate_name") String rateName); @Param("clean_days") Integer cleanDays, @Param("rate_name") String rateName);
List<JSONObject> minExpiryTime(@Param("client_id")int client_id,@Param("rate_name") String rate_name);
List<JSONObject> latestConfig(@Param("client_id")int client_id,@Param("rate_name") String rate_name); List<JSONObject> latestConfig(@Param("client_id")int client_id,@Param("rate_name") String rate_name);
//Task
List<JSONObject> maxChannelExpiryTime(@Param("client_id")int client_id,@Param("rate_name")String rate_name);
List<JSONObject> getAllExpiry(@Param("expiry_date")Date expiry_date);
JSONObject latestChannelCleanDays(@Param("rate_name")String rate_name, @Param("client_id")int client_id);
} }

@ -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;
}
}

@ -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.connections.mpsupport.beans.TemplateMessage;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.env.SysConfigManager; import au.com.royalpay.payment.tools.env.SysConfigManager;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
/** /**
* Created by Tayl0r on 2017/7/6. * Created by Tayl0r on 2017/7/6.
@ -84,8 +85,6 @@ public class NoticeRefundReviewListener implements ApplicationListener<NewRefund
private TemplateMessage initMessage(NewRefundReviewEvent newRefundReviewEvent, String operatorName, JSONObject client, JSONObject review, String templateId, String wechatOpenid) { 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 uri = "/api/payment/v1.0/refund/review/" + review.getString("review_id");
logger.debug("kiratest->>>>>"+review.getString("review_id"));
logger.debug("kiratest->>>>>"+review.toJSONString());
String loginUrl = PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat") + "?target=" + uri; String loginUrl = PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat") + "?target=" + uri;
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, loginUrl); TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, loginUrl);
notice.put("first", operatorName + "提交了订单的退款申请,请审核", "#ff0000"); notice.put("first", operatorName + "提交了订单的退款申请,请审核", "#ff0000");
@ -99,8 +98,6 @@ public class NoticeRefundReviewListener implements ApplicationListener<NewRefund
private TemplateMessage initMessageToOperator(NewRefundReviewEvent newRefundReviewEvent, String operatorName, JSONObject client, JSONObject review, String templateId, String wechatOpenid) { private TemplateMessage initMessageToOperator(NewRefundReviewEvent newRefundReviewEvent, String operatorName, JSONObject client, JSONObject review, String templateId, String wechatOpenid) {
String uri = PlatformEnvironment.getEnv().concatUrl("/api/payment/v1.0/refund/review/check/" + review.getString("review_id")); String uri = PlatformEnvironment.getEnv().concatUrl("/api/payment/v1.0/refund/review/check/" + review.getString("review_id"));
logger.debug("kiratestOperator->>>>>"+review.getString("review_id"));
logger.debug("kiratestOperator->>>>>"+review.toJSONString());
TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, uri); TemplateMessage notice = new TemplateMessage(wechatOpenid, templateId, uri);
notice.put("first", operatorName + ",您的退款申请已提交请等待RoyalPay审核", "#ff0000"); notice.put("first", operatorName + ",您的退款申请已提交请等待RoyalPay审核", "#ff0000");
notice.put("keyword1", review.getString("currency") + newRefundReviewEvent.getRefundOrder().getDoubleValue("amount"), "#ff0000"); notice.put("keyword1", review.getString("currency") + newRefundReviewEvent.getRefundOrder().getDoubleValue("amount"), "#ff0000");

@ -87,20 +87,35 @@
order by update_time desc order by update_time desc
]]> ]]>
</select> </select>
<select id="minExpiryTime" resultType="com.alibaba.fastjson.JSONObject"> <select id="maxChannelExpiryTime" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM select cr.* ,c.client_moniker from sys_client_rates cr
sys_client_rates 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 client_id = #{client_id} where cr.client_id = #{client_id}
AND active_time = <if test="rate_name != null">
( and cr.rate_name = #{rate_name}
SELECT max(active_time) FROM sys_client_rates </if>
WHERE client_id = #{client_id} group by cr.client_id, cr.rate_name
)
and rate_name in('Wechat','Alipay')
order by expiry_time desc
</select> </select>
<select id="getAllExpiry" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT a.*
FROM
(SELECT
cr.client_id ,
cr.active_time ,
max(cr.expiry_time) expiry_time ,
cr.rate_name
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)
GROUP BY
cr.client_id ,cr.rate_name
) a
WHERE
a.expiry_time < #{expiry_date}
]]>
</select>
<select id="latestConfig" resultType="com.alibaba.fastjson.JSONObject"> <select id="latestConfig" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM SELECT * FROM
sys_client_rates sys_client_rates
@ -112,4 +127,13 @@
) )
order by expiry_time desc order by expiry_time desc
</select> </select>
<select id="latestChannelCleanDays" resultType="com.alibaba.fastjson.JSONObject">
select cr.*,c.clean_days c_clean_days 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}
order by cr.expiry_time desc
limit 1
</select>
</mapper> </mapper>
Loading…
Cancel
Save