|
|
|
@ -2,24 +2,30 @@ package au.com.royalpay.payment.manage.riskbusiness.core.impl;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.core.exceptions.EmailException;
|
|
|
|
|
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.AppMessageLogMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskEventMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskFileMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskMaterialMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientDeviceTokenMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery;
|
|
|
|
|
import au.com.royalpay.payment.manage.notice.core.MailService;
|
|
|
|
|
import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder;
|
|
|
|
|
import au.com.royalpay.payment.manage.riskbusiness.core.RiskBusinessService;
|
|
|
|
|
import au.com.royalpay.payment.manage.riskbusiness.enums.RiskResultTypeEnum;
|
|
|
|
|
import au.com.royalpay.payment.manage.signin.beans.TodoNotice;
|
|
|
|
|
import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider;
|
|
|
|
|
import au.com.royalpay.payment.manage.tradelog.core.TradeLogService;
|
|
|
|
|
import au.com.royalpay.payment.manage.riskbusiness.enums.RiskOrderTypeEnum;
|
|
|
|
|
import au.com.royalpay.payment.tools.device.message.AppMessage;
|
|
|
|
|
import au.com.royalpay.payment.tools.device.message.AppMsgSender;
|
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
import au.com.royalpay.payment.tools.locale.LocaleSupport;
|
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
import au.com.royalpay.payment.tools.threadpool.RoyalThreadPoolExecutor;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
@ -44,10 +50,10 @@ import org.thymeleaf.spring4.SpringTemplateEngine;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
@ -85,6 +91,14 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
|
|
|
|
|
private RiskMaterialMapper riskMaterialMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private RiskFileMapper riskFileMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientDeviceTokenMapper clientDeviceTokenMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private AppMessageLogMapper appMessageLogMapper;
|
|
|
|
|
|
|
|
|
|
private Map<String, AppMsgSender> senderMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private ThreadPoolExecutor sendingAppleMsgPool = new ThreadPoolExecutor(10, 30, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> getRiskEvents(JSONObject params) {
|
|
|
|
@ -231,6 +245,66 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
|
|
|
|
|
throw new EmailException("Email Sending Failed", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if(event.getIntValue("order_type")==3){
|
|
|
|
|
sendAppRiskMessage(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendAppRiskMessage(JSONObject event){
|
|
|
|
|
JSONObject client = clientMapper.findClientByMoniker(event.getString("client_moniker"));
|
|
|
|
|
logger.debug("sendRiskAppMessage-" + client.getString("client_moniker") + "-" + "risk_id:"+event.getString("risk_id"));
|
|
|
|
|
List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByClient_id(client.getIntValue("client_id"));
|
|
|
|
|
for (final JSONObject devToken : tokens) {
|
|
|
|
|
Runnable task = () -> {
|
|
|
|
|
String token = devToken.getString("token");
|
|
|
|
|
if (token == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "risk", token,
|
|
|
|
|
event.getString("risk_id"));
|
|
|
|
|
try {
|
|
|
|
|
event.put("send_type", "risk");
|
|
|
|
|
JSONObject type = new JSONObject();
|
|
|
|
|
type.put("send_type", "risk");
|
|
|
|
|
type.put("id", event.getString("risk_id"));
|
|
|
|
|
AppMsgSender sender = senderMap.get(devToken.getString("client_type"));
|
|
|
|
|
if (token == null || sender == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
JSONObject managerMsg = new JSONObject();
|
|
|
|
|
managerMsg.put("title", LocaleSupport.localeMessage("app.message.title.risk"));
|
|
|
|
|
managerMsg.put("body",
|
|
|
|
|
LocaleSupport.localeMessage("app.message.body.risk"));
|
|
|
|
|
managerMsg.put("type", type);
|
|
|
|
|
managerMsg.put("data", event);
|
|
|
|
|
managerMsg.put("msgType", "risk");
|
|
|
|
|
AppMessage appMessage = new AppManagerMessageBuilder(managerMsg).buildMessage();
|
|
|
|
|
sender.sendMessage(appMessage, devToken);
|
|
|
|
|
log.put("status", 2);
|
|
|
|
|
appMessageLogMapper.update(log);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("出错了:" + e.getMessage());
|
|
|
|
|
appMessageLogMapper.updateStatus(log.getString("send_id"), 1, e.getMessage());
|
|
|
|
|
throw new ServerErrorException("Send App " + devToken.getString("client_type") + " Failed", e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
sendingAppleMsgPool.execute(task);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JSONObject saveAppMessageLog(String dev_id, int client_id, String messageType, String dev_token, String remark) {
|
|
|
|
|
JSONObject log = new JSONObject();
|
|
|
|
|
log.put("dev_id", dev_id);
|
|
|
|
|
log.put("client_id", client_id);
|
|
|
|
|
log.put("msg_type", messageType);
|
|
|
|
|
log.put("dev_token", dev_token);
|
|
|
|
|
log.put("remark", remark);
|
|
|
|
|
log.put("send_time", new Date());
|
|
|
|
|
appMessageLogMapper.save(log);
|
|
|
|
|
return log;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|