@ -12,7 +12,6 @@ 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 ;
@ -146,15 +145,26 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
}
@Override
public List < JSONObject > getRiskEventOrderList ( String orderIds ) {
public List < JSONObject > getRiskEventOrderList ( JSONObject riskEvent ) {
String orderIds = riskEvent . getString ( "order_ids" ) ;
JSONObject client = clientMapper . findClientByMonikerAll ( riskEvent . getString ( "client_moniker" ) ) ;
List < JSONObject > tradeLogs = new ArrayList < > ( ) ;
if ( StringUtils . isNotBlank ( orderIds ) ) {
String [ ] orderIdArray = orderIds . trim ( ) . split ( "," ) ;
JSONObject query = new JSONObject ( ) ;
JSONObject orderInfo = new JSONObject ( ) ;
String realOrderId = "" ;
// 获取订单信息
for ( int i = 0 ; i < orderIdArray . length ; i + + ) {
JSONObject orderInfo = orderMapper . findOrderById ( orderIdArray [ i ] ) ;
tradeLogs . add ( orderInfo ) ;
if ( riskEvent . getIntValue ( "order_type" ) = = 3 ) {
for ( int i = 0 ; i < orderIdArray . length ; i + + ) {
realOrderId = orderMapper . findOrderById ( orderIdArray [ i ] , client . getIntValue ( "client_id" ) ) . getString ( "order_id" ) ;
orderInfo = tradeLogService . getOrderDetail ( new JSONObject ( ) , riskEvent . getString ( "client_moniker" ) , realOrderId , null ) ;
tradeLogs . add ( orderInfo ) ;
}
} else {
for ( int i = 0 ; i < orderIdArray . length ; i + + ) {
orderInfo = orderMapper . findOrderById ( orderIdArray [ i ] , client . getIntValue ( "client_id" ) ) ;
tradeLogs . add ( orderInfo ) ;
}
}
}
return tradeLogs ;
@ -183,7 +193,7 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
String [ ] orderIdArray = orderIds . split ( "," ) ;
List < String > orderAmountList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < orderIdArray . length ; i + + ) {
JSONObject orderInfo = orderMapper . findOrderById ( orderIdArray [ i ] );
JSONObject orderInfo = orderMapper . findOrderById ( orderIdArray [ i ] ,client . getIntValue ( "client_id" ) );
// 判断该笔订单是否存在,是否属于该商户
if ( orderInfo = = null )
throw new OrderNotExistsException ( ) ;
@ -252,7 +262,7 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
royalThreadPoolExecutor . execute ( ( ) - > {
try {
String emailId = mailService . sendRiskEmail ( title , emailsTos . isEmpty ( ) ? "" : StringUtils . join ( emailsTos , "," ) ,
emailsCcs . isEmpty ( ) ? "" : StringUtils . join ( emailsCcs , "," ) , content , event . getIntValue ( "order_type" ) = = 3 ? ( List < JSONObject > ) ctx . getVariable ( "files" ) : null , event . getIntValue ( "order_type" ) ) ;
emailsCcs . isEmpty ( ) ? "" : StringUtils . join ( emailsCcs , "," ) , "" , content , null , event . getIntValue ( "order_type" ) ) ;
event . put ( "email_status" , 1 ) ;
event . put ( "result_type" , RiskResultTypeEnum . SEND_EMAIL_TO_BD . getResultType ( ) ) ;
event . put ( "submit_url" , uploadUrl ) ;
@ -339,7 +349,7 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
royalThreadPoolExecutor . execute ( ( ) - > {
try {
String emailId = mailService . sendRiskEmail ( "You need to resubmit risk materials" , emailsTos . isEmpty ( ) ? "" : StringUtils . join ( emailsTos , "," ) ,
emailsCcs . isEmpty ( ) ? "" : StringUtils . join ( emailsCcs , "," ) , content , event . getIntValue ( "order_type" ) = = 3 ? ( List < JSONObject > ) ctx . getVariable ( "files" ) : null , event . getIntValue ( "order_type" ) ) ;
emailsCcs . isEmpty ( ) ? "" : StringUtils . join ( emailsCcs , "," ) , "" , content , null , event . getIntValue ( "order_type" ) ) ;
event . put ( "email_status" , 2 ) ;
event . put ( "result_type" , RiskResultTypeEnum . MATERIAL_NOT_PASS . getResultType ( ) ) ;
event . put ( "submit_url" , uploadUrl ) ;
@ -360,7 +370,7 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
royalThreadPoolExecutor . execute ( ( ) - > {
try {
String emailId = mailService . sendRiskEmail ( "Please submit risk materials as soon as possible" , emailsTos . isEmpty ( ) ? "" : StringUtils . join ( emailsTos , "," ) ,
emailsCcs . isEmpty ( ) ? "" : StringUtils . join ( emailsCcs , "," ) , content , event . getIntValue ( "order_type" ) = = 3 ? ( List < JSONObject > ) ctx . getVariable ( "files" ) : null , event . getIntValue ( "order_type" ) ) ;
emailsCcs . isEmpty ( ) ? "" : StringUtils . join ( emailsCcs , "," ) , "" , content , null , event . getIntValue ( "order_type" ) ) ;
event . put ( "email_status" , 3 ) ;
riskEventMapper . update ( event ) ;
} catch ( Exception e ) {
@ -370,7 +380,8 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
}
private Context getMailContext ( JSONObject event ) throws IOException {
JSONObject client = clientMapper . findClientByMonikerAll ( event . getString ( "client_moniker" ) ) ;
String clientMoniker = event . getString ( "client_moniker" ) ;
JSONObject client = clientMapper . findClientByMonikerAll ( clientMoniker ) ;
if ( client = = null ) {
throw new InvalidShortIdException ( ) ;
}
@ -379,12 +390,20 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
codeKey = RandomStringUtils . random ( 20 , true , true ) ;
}
String codeKeyValue = RandomStringUtils . random ( 10 , true , true ) ;
/ *
String expireDay = "7" ;
if ( event . getIntValue ( "order_type" ) > 2 ) {
expireDay = "3" ;
}
) * /
// 原来设定的过期时间是7天, 现在改成一个月
String expireDay = "30" ;
stringRedisTemplate . boundValueOps ( getRiskUploadKey ( codeKey ) ) . set ( codeKeyValue , Long . parseLong ( expireDay ) , TimeUnit . DAYS ) ;
String uploadUrl = PlatformEnvironment . getEnv ( ) . concatUrl ( "/risk/upload/" ) + event . getString ( "risk_id" ) + "/" + codeKey ;
int orderType = event . getIntValue ( "order_type" ) ;
if ( orderType = = 1 | | orderType = = 2 )
uploadUrl = PlatformEnvironment . getEnv ( ) . concatUrl ( "/manage.html#/analysis/monitoring/" ) + event . getString ( "risk_id" ) + "/bd/detail?codeKey=" + codeKey ;
//uploadUrl = "localhost:9009" + "/manage.html#/analysis/monitoring/" + event.getString("risk_id") + "/bd/detail";
List < JSONObject > bds = clientBDMapper . listClientBDInfoAvailable ( client . getIntValue ( "client_id" ) , new Date ( ) ) ;
List < String > bdNames = new ArrayList < > ( ) ;
List < String > bdEmails = new ArrayList < > ( ) ;
@ -403,8 +422,10 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
String bdNamesStr = bdNames . isEmpty ( ) ? "" : StringUtils . join ( bdNames , "," ) ;
String reply_date = DateFormatUtils . format ( DateUtils . addDays ( event . getDate ( "reply_email_date" ) , - 1 ) , "yyyy年MM月dd日" ) ;
String reply_date_english = DateFormatUtils . format ( DateUtils . addDays ( event . getDate ( "reply_email_date" ) , - 1 ) , "dd/MM/yyyy" ) ;
GregorianCalendar gregorianCalendar = new GregorianCalendar ( ) ;
String hello = gregorianCalendar . get ( GregorianCalendar . AM_PM ) = = 0 ? "上午好" : "下午好" ;
Context ctx = new Context ( ) ;
ctx . setVariable ( "hello" , hello ) ;
ctx . setVariable ( "order_type" , event . getIntValue ( "order_type" ) ) ;
ctx . setVariable ( "bdNamesStr" , bdNamesStr ) ;
ctx . setVariable ( "reply_date" , reply_date ) ;
@ -413,13 +434,13 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
ctx . setVariable ( "uploadUrl" , uploadUrl ) ;
ctx . setVariable ( "royalpay_order_type" , event . getIntValue ( "royalpay_order_type" ) ) ;
ctx . setVariable ( "warning_order_type" , event . getIntValue ( "warning_order_type" ) ) ;
String [ ] orderIds = event . getString ( "order_ids" ) . split ( "," ) ;
List < JSONObject > orders = new ArrayList ( ) ;
switch ( event . getIntValue ( "order_type" ) ) {
case 1 :
case 2 :
String [ ] orderIds = event . getString ( "order_ids" ) . split ( "," ) ;
List < JSONObject > orders = new ArrayList ( ) ;
for ( String orderId : orderIds ) {
JSONObject order = orderMapper . findOrderById ( orderId );
JSONObject order = orderMapper . findOrderById ( orderId , client . getIntValue ( "client_id" ) ) ;
if ( order = = null ) {
throw new BadRequestException ( "Order: " + orderId + " not exists" ) ;
}
@ -430,12 +451,30 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
ctx . setVariable ( "emailsTos" , bdEmails ) ;
break ;
case 3 :
List < JSONObject > attachList = new ArrayList < > ( ) ;
JSONObject file = new JSONObject ( ) ;
file . put ( "name" , client . getString ( "short_name" ) + "被查单号相关信息.xlsx" ) ;
file . put ( "content" , Base64 . encodeBase64String ( generateRiskOrders ( event ) ) ) ;
attachList . add ( file ) ;
ctx . setVariable ( "files" , attachList ) ;
String realOrderId = "" ;
for ( String orderId : orderIds ) {
realOrderId = orderMapper . findOrderById ( orderId , client . getIntValue ( "client_id" ) ) . getString ( "order_id" ) ;
JSONObject order = tradeLogService . getOrderDetail ( new JSONObject ( ) , clientMoniker , realOrderId , null ) ;
if ( order = = null ) {
throw new BadRequestException ( "Order: " + orderId + " not exists" ) ;
}
order . put ( "order_description" , StringUtils . defaultString ( order . getString ( "order_description" ) ) ) ;
order . put ( "gateway" , getGateWay ( order . getIntValue ( "gateway" ) ) ) ;
order . put ( "status" , getStatus ( order . getIntValue ( "status" ) ) ) ;
order . put ( "order_detail" , StringUtils . defaultString ( order . getString ( "order_detail" ) ) ) ;
order . put ( "total_amount" , order . getString ( "currency" ) + " " + order . getString ( "total_amount" ) ) ;
order . put ( "display_amount" , order . getString ( "currency" ) + " " + order . getString ( "display_amount" ) ) ;
order . put ( "customer_payment_amount" , order . getString ( "currency" ) + " " + order . getString ( "customer_payment_amount" ) ) ;
order . put ( "clearing_amount" , "AUD " + order . getString ( "clearing_amount" ) ) ;
orders . add ( order ) ;
}
ctx . setVariable ( "orders" , orders ) ;
// List<JSONObject> attachList = new ArrayList<>();
// JSONObject file = new JSONObject();
// file.put("name", client.getString("short_name")+ "被查单号相关信息.xlsx");
// file.put("content", Base64.encodeBase64String(generateRiskOrders(event)));
// attachList.add(file);
// ctx.setVariable("files",attachList);
case 4 :
ctx . setVariable ( "title" , "RoyalPay风控调查 — " + client . getString ( "short_name" ) ) ;
ctx . setVariable ( "emailsCcs" , bdEmails ) ;
@ -473,11 +512,16 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
return null ;
}
private byte [ ] generateRiskOrders ( JSONObject event ) throws IOException {
String [ ] orderIds = event . getString ( "order_ids" ) . split ( "," ) ;
JSONObject client = clientMapper . findClientByMonikerAll ( event . getString ( "client_moniker" ) ) ;
Workbook wb = new XSSFWorkbook ( ) ;
String realOrderId = "" ;
for ( String orderId : orderIds ) {
JSONObject orderDetail = tradeLogService . getOrderDetail ( new JSONObject ( ) , event . getString ( "client_moniker" ) , orderId , null ) ;
realOrderId = orderMapper . findOrderById ( orderId , client . getIntValue ( "client_id" ) ) . getString ( "order_id" ) ;
JSONObject orderDetail = tradeLogService . getOrderDetail ( new JSONObject ( ) , event . getString ( "client_moniker" ) , realOrderId , null ) ;
Sheet sheet = wb . createSheet ( orderId ) ;
sheet . setDefaultColumnWidth ( ( short ) 40 ) ;
Row row0 = sheet . createRow ( 0 ) ;