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