Merge branch 'develop'

master
taylor.dang 4 years ago
commit 63355f405e

@ -9,7 +9,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId>
<version>2.3.47</version>
<version>2.3.48</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>2.4.0</jib-maven-plugin.version>

@ -51,4 +51,6 @@ public interface ClientAnalysisMapper {
List<JSONObject> tradeSubMerchantIdBy60Days(@Param("begin") Date begin);
List<JSONObject> countClientsSettlementCycle(JSONObject params);
List<JSONObject> listSecurePayMchs();
}

@ -579,4 +579,9 @@ public class TestController {
params.put("client_moniker", clientMoniker);
return params;
}
@GetMapping(value = "/securepay/settle/file")
public void sendSecurePaySettleFile() {
tradeSecureService.sendSecurePaySettleFile("20200803");
}
}

@ -16,4 +16,6 @@ public interface TradeSecureService {
void manualDownloadHanyinSecureReport(Date date, boolean upload, HttpServletResponse resp);
TradeSecureFile getSecureReportFile(Date date);
void sendSecurePaySettleFile(String dateStr);
}

@ -1,12 +1,17 @@
package au.com.royalpay.payment.manage.system.core.impl;
import au.com.royalpay.payment.core.exceptions.ChannelNetworkException;
import au.com.royalpay.payment.manage.analysis.mappers.ClientAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.system.core.TradeSecureService;
import au.com.royalpay.payment.manage.system.core.beans.TradeSecureFile;
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery;
import au.com.royalpay.payment.manage.tradelog.core.TradeLogService;
import au.com.royalpay.payment.tools.env.SysConfigManager;
import com.alibaba.fastjson.JSONObject;
import com.jcraft.jsch.*;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.provider.sftp.SftpClientFactory;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
@ -40,10 +45,18 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService {
private String sftpUsername;
@Value("${app.hanyin-secure.sftp-pwd}")
private String sftpPwd;
@Value("${app.securepay.sftp.username:upitest}")
private String securePaySftpName;
@Value("${app.securepay.sftp.password:upitest}")
private String securePaySftpPwd;
@Resource
private TransactionMapper transactionMapper;
@Resource
private ClientAnalysisMapper clientAnalysisMapper;
@Resource
private SysConfigManager sysConfigManager;
@Resource
private TradeLogService tradeLogService;
@Override
public void uploadSecureReportYesterday() {
@ -119,4 +132,51 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService {
file.addTransactions(debits);
return file;
}
@Override
public void sendSecurePaySettleFile(String dateStr) {
List<JSONObject> scpayMchs = clientAnalysisMapper.listSecurePayMchs();
scpayMchs.forEach(mch -> {
TradeLogQuery query = new TradeLogQuery();
query.setDatefrom(dateStr);
query.setDatefrom(dateStr);
byte[] fileData = tradeLogService.exportPDFSettlement(query, mch);
String fileName = dateStr + "-SETTLEMENT-" + RandomStringUtils.random(9, true, true).toUpperCase() + "-"
+ mch.getString("client_moniker") + ".pdf";
sendSftpFile(dateStr, fileName, fileData);
});
}
private void sendSftpFile(String dateStr, String fileName, byte[] data) {
Session session = null;
ChannelSftp command = null;
try {
session = initSFTPConnection(securePaySftpName, securePaySftpPwd);
Channel channel = session.openChannel("sftp");
channel.connect();
command = (ChannelSftp) channel;
try {
command.put(new ByteArrayInputStream(data), "/" + StringUtils.substring(dateStr, 0, 6) + "/" + fileName);
logger.info("文件发送成功!");
} catch (SftpException e) {
logger.error(e.getMessage());
}
} catch (IOException | JSchException e) {
throw new ChannelNetworkException("Send Settlement file failed", e);
} finally {
if (command != null && command.isConnected()) {
command.exit();
session.disconnect();
}
}
}
private Session initSFTPConnection(String sftpUsername, String sftpPassword) throws IOException {
FileSystemOptions fso = new FileSystemOptions();
return SftpClientFactory.createConnection("124.156.126.236", 2022,
sftpUsername.toCharArray(), sftpPassword.toCharArray(), fso);
}
}

@ -0,0 +1,28 @@
package au.com.royalpay.payment.manage.task;
import au.com.royalpay.payment.manage.system.core.TradeSecureService;
import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
@Component
@ConditionalOnProperty(value = "app.run-tasks", havingValue = "true")
public class SecurePaySettleFileTask {
@Resource
private SynchronizedScheduler synchronizedScheduler;
@Resource
private TradeSecureService tradeSecureService;
@Scheduled(cron = "0 0 3 * * *")
public void sendSecurePaySettleFile() {
synchronizedScheduler.executeProcess("task:securepay_settle_file_sending", 60_000, () ->
tradeSecureService.sendSecurePaySettleFile(DateFormatUtils.format(new Date(), "yyyyMMdd"))
);
}
}

@ -69,6 +69,8 @@ public interface TradeLogService {
void exportPDFSettlement(TradeLogQuery query, JSONObject partner, HttpServletResponse response);
byte[] exportPDFSettlement(TradeLogQuery query, JSONObject client);
void exportExcelAllPartner(TradeLogQuery query, JSONObject partner, HttpServletResponse httpResponse) throws Exception;
}

@ -1975,6 +1975,50 @@ public class TradeLogServiceImpl implements TradeLogService {
}
}
@Override
public byte[] exportPDFSettlement(TradeLogQuery query, JSONObject client) {
String begin = query.getDatefrom() == null ? "" : query.getDatefrom();
String end = query.getDateto() == null ? "" : query.getDateto();
String timezone = client.getString("timezone");
JSONObject params = query.toParams(timezone);
if (params.get("client_ids") == null) {
params.put("client_id", client.getString("client_id"));
}
clientManager.queryModifyClientIds(client.getIntValue("client_id"), params);
List<JSONObject> clientOrderList = transactionMapper.getClientOrderByTransactionTime(params);
JSONObject parmerters = new JSONObject();
parmerters.put("dateRange", "(Statement Period " + begin + "~"
+ end + ")");
parmerters.put("clientName", client.getString("company_name"));
parmerters.put("clientAddress", client.getString("address"));
parmerters.put("clientLocation", client.getString("suburb") + "," + client.getString("state") + "," + client.getString("postcode"));
List<JSONObject> settlementLogDetailList = new ArrayList<>();
try {
parmerters.put("logo", logo.getInputStream());
if (clientOrderList.size() > 0) {
List<Integer> clientOrders = new ArrayList<>(clientOrderList.size());
clientOrderList.parallelStream().forEach(p -> clientOrders.add(p.getInteger("clearing_order")));
settlementLogDetailList = transactionMapper.getSettlementLogDetailList(clientOrders);
TimeZoneUtils.switchTimeZoneToString(settlementLogDetailList, timezone, "yyyy-MM-dd HH:mm:ss", Collections.singletonList("transaction_time"));
settlementLogDetailList.parallelStream().forEach(item -> {
scaleDecimalVal(item, "display_amount", item.getString("transaction_currency"));
String platformCurrency = PlatformEnvironment.getEnv().getForeignCurrency();
scaleDecimalVal(item, "clearing_amount", platformCurrency);
scaleDecimalVal(item, "settle_amount", platformCurrency);
scaleDecimalVal(item, "total_surcharge", platformCurrency);
scaleDecimalVal(item, "transaction_amount", platformCurrency);
item.put("exchange_rate", item.getBigDecimal("exchange_rate").setScale(5, RoundingMode.DOWN));
item.put("gateway", item.getInteger("gateway") == null ? "-" : TradeType.fromGatewayNumber(item.getIntValue("gateway")).getTradeType());
item.put("rate", item.getBigDecimal("rate") == null ? "-" : item.getBigDecimal("rate").toPlainString() + "%");
});
}
JRDataSource jrDataSource = new JRBeanCollectionDataSource(settlementLogDetailList);
return JasperRunManager.runReportToPdf(partner_settlement_flow.getInputStream(), parmerters, jrDataSource);
} catch (Exception e) {
throw new ServerErrorException(e);
}
}
@Override
public void exportExcelAllPartner(TradeLogQuery query, JSONObject partner, HttpServletResponse resp) throws
Exception {

@ -10,7 +10,8 @@
]]>
<if test="org_id!=null and org_ids==null">and org_id=#{org_id}</if>
<if test="org_ids!=null">and org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
</select>
<select id="countNewClientsHistory" resultType="com.alibaba.fastjson.JSONObject">
@ -29,7 +30,8 @@
]]>
<if test="org_id!=null and org_ids==null">and c.org_id=#{org_id}</if>
<if test="org_ids!=null">and c.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
<if test="bd_group!=null">and c.client_id in
(SELECT b.client_id FROM sys_client_bd b
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id
@ -50,7 +52,8 @@
]]>
<if test="org_id!=null and org_ids==null">and org_id=#{org_id}</if>
<if test="org_ids!=null">and org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
</select>
<!--显示所有的商户,包括禁用的-->
@ -77,7 +80,8 @@
]]>
<if test="org_id!=null and org_ids==null">and org_id=#{org_id}</if>
<if test="org_ids!=null">and org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
GROUP BY YEAR(create_time),MONTH(create_time),DAY(create_time) ORDER BY create_time desc
</select>
@ -90,7 +94,8 @@
]]>
<if test="org_id!=null and org_ids==null">and org_id=#{org_id}</if>
<if test="org_ids!=null">and org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
</select>
<select id="countTradedPartners" resultType="java.lang.Integer">
<![CDATA[
@ -101,7 +106,8 @@
]]>
<if test="org_id!=null and org_ids==null">and p.org_id=#{org_id}</if>
<if test="org_ids!=null">and p.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
</select>
<select id="countTradePartnersHistory" resultType="com.alibaba.fastjson.JSONObject">
@ -113,7 +119,8 @@
]]>
<if test="org_id!=null and org_ids==null">and p.org_id=#{org_id}</if>
<if test="org_ids!=null">and p.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
<if test="bd_group!=null">and p.client_id in
(SELECT b.client_id FROM sys_client_bd b
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id
@ -239,7 +246,8 @@
is_valid = 1 and industry &lt;'400' AND approve_result=1
<if test="org_id!=null and org_ids==null">and org_id=#{org_id}</if>
<if test="org_ids!=null">and org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
<if test="bd_group!=null">and c.client_id in
(SELECT b.client_id FROM sys_client_bd b
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id
@ -254,6 +262,7 @@
<select id="notTradeSubMerchantId" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT COUNT(DISTINCT c.client_id) client_count,
c.sub_merchant_id,
c.merchant_id
@ -269,6 +278,7 @@
<select id="tradeSubMerchantIdBy60Days" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT COUNT(DISTINCT c.client_id) client_count,
c.sub_merchant_id,
c.merchant_id,
@ -302,7 +312,8 @@
(c.approve_result = 1 OR c.approve_result= 2) AND c.is_valid = 1
<if test="org_id!=null and org_ids==null">and org_id=#{org_id}</if>
<if test="org_ids!=null">and org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
<if test="bd_group!=null">and c.client_id in
(SELECT b.client_id FROM sys_client_bd b
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id
@ -319,9 +330,13 @@
<if test="eng!=null">
o.date > #{end}
</if>
</where>)
</where>
)
</if>
</where>
GROUP by c.clean_days
</select>
<select id="listSecurePayMchs" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM sys_clients sc where sc.org_id in (112,113) and is_valid=1
</select>
</mapper>

Loading…
Cancel
Save