Merge branch 'develop_postpone' into develop

master
wangning 7 years ago
commit baec160c2d

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

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

@ -0,0 +1,144 @@
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.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;
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;
@Resource
private ManagerMapper managerMapper;
// @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;
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", yearTomorrow);
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);
});
adminAccounts.forEach(o -> {
sendClientPostponeNotify(o, expireDate);
});
});
sendComplianceNotify(expiryClients, expireDate);
}
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("client-postpone");
if (templateId != null) {
TemplateMessage notice = initClientMessage(client,newExpireDate,account.getString("wechat_openid"),templateId);
api.sendTemplateMessage(notice);
}
}
} catch (Exception e) {
logger.error("Sending Notify failure", e);
}
}
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 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;
}
}

@ -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<NewRefund
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");
logger.debug("kiratest->>>>>"+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<NewRefund
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"));
logger.debug("kiratestOperator->>>>>"+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");

@ -87,20 +87,36 @@
order by update_time desc
]]>
</select>
<select id="minExpiryTime" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM
sys_client_rates
WHERE client_id = #{client_id}
AND active_time =
(
SELECT max(active_time) FROM sys_client_rates
WHERE client_id = #{client_id}
)
and rate_name in('Wechat','Alipay')
order by expiry_time desc
<select id="maxChannelExpiryTime" resultType="com.alibaba.fastjson.JSONObject">
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}
<if test="rate_name != null">
and cr.rate_name = #{rate_name}
</if>
group by cr.client_id, cr.rate_name
</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,
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)
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 * FROM
sys_client_rates
@ -112,4 +128,13 @@
)
order by expiry_time desc
</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>

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