secure upload

master
yixian 8 years ago
parent 3ac82ce0e3
commit e43b4b0f42

@ -8,8 +8,6 @@ import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList; import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@ -102,6 +100,7 @@ public interface TransactionMapper {
BigDecimal TotalAmountForBDPrize(@Param("year") int year, @Param("month") int month, @Param("bd_id") String bd_id); BigDecimal TotalAmountForBDPrize(@Param("year") int year, @Param("month") int month, @Param("bd_id") String bd_id);
BigDecimal TotalAmountForBDLeaderPrize(@Param("year") int year, @Param("month") int month, @Param("bd_group") String bd_group); BigDecimal TotalAmountForBDLeaderPrize(@Param("year") int year, @Param("month") int month, @Param("bd_group") String bd_group);
BigDecimal TotalAmountForSydneyGMPrize(@Param("year") int year, @Param("month") int month); BigDecimal TotalAmountForSydneyGMPrize(@Param("year") int year, @Param("month") int month);
List<JSONObject> listTransactionForCityPartnerCommissionByDate(@Param("year") int year, @Param("month") int month); List<JSONObject> listTransactionForCityPartnerCommissionByDate(@Param("year") int year, @Param("month") int month);
@ -120,9 +119,9 @@ public interface TransactionMapper {
@AdvanceSelect(addonWhereClause = "transaction_type='Credit'") @AdvanceSelect(addonWhereClause = "transaction_type='Credit'")
int countOrders(@Param("client_id") int client_id); int countOrders(@Param("client_id") int client_id);
List<JSONObject> listDailyTransactions(@Param("from") Date from, @Param("to") Date to, @Param("dev_id") String devId, @Param("client_id") int clientId,@Param("client_ids")String [] client_ids); List<JSONObject> listDailyTransactions(@Param("from") Date from, @Param("to") Date to, @Param("dev_id") String devId, @Param("client_id") int clientId, @Param("client_ids") String[] client_ids);
JSONObject analysisRetailDailyReport(@Param("from") Date from, @Param("to") Date to, @Param("dev_id") String devId, @Param("client_id") int clientId,@Param("client_ids")String [] client_ids); JSONObject analysisRetailDailyReport(@Param("from") Date from, @Param("to") Date to, @Param("dev_id") String devId, @Param("client_id") int clientId, @Param("client_ids") String[] client_ids);
@AutoSql(type = SqlType.SELECT) @AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "system_generate=1") @AdvanceSelect(addonWhereClause = "system_generate=1")
@ -156,6 +155,7 @@ public interface TransactionMapper {
/** /**
* 付款退款都是同一个退款单号 * 付款退款都是同一个退款单号
*
* @param clientId * @param clientId
* @param systemTransactionId * @param systemTransactionId
* @return * @return
@ -164,4 +164,8 @@ public interface TransactionMapper {
PageList<JSONObject> findByClientIdAndSystemTransactionId(@Param("client_id") int clientId, PageList<JSONObject> findByClientIdAndSystemTransactionId(@Param("client_id") int clientId,
@Param("system_transaction_id") String systemTransactionId, @Param("system_transaction_id") String systemTransactionId,
PageBounds pageBounds); PageBounds pageBounds);
List<JSONObject> listCreditTransactionsForSecure(Date from, Date to);
List<JSONObject> listDebitTransactionsForSecure(Date from, Date to);
} }

@ -0,0 +1,17 @@
package au.com.royalpay.payment.manage.system.core;
import au.com.royalpay.payment.manage.system.core.beans.TradeSecureFile;
import java.util.Date;
/**
* Create by yixian at 2019-01-08 3:17
*/
public interface TradeSecureService {
void uploadSecureReportYesterday();
void uploadSecureReport(Date date);
TradeSecureFile getSecureReportFile(Date date);
}

@ -0,0 +1,149 @@
package au.com.royalpay.payment.manage.system.core.beans;
import au.com.royalpay.payment.tools.defines.TradeType;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
import com.alibaba.fastjson.JSONObject;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.stream.Collectors;
/**
* Create by yixian at 2019-01-08 3:27
*/
public class TradeSecureFile {
private static final DateTimeZone zone = DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
private final String pid;
private final DateTime transDate;
private final DateTime createTime;
private List<TradeItem> tradeItems;
private byte[] content;
public TradeSecureFile(String pid, Date transDate) {
this.pid = pid;
this.transDate = new DateTime(transDate).withZoneRetainFields(zone).withMillisOfDay(0);
this.tradeItems = new ArrayList<>();
this.createTime = DateTime.now(zone);
}
public DateTime getTransDate() {
return transDate;
}
public Date getFromTime() {
return transDate.withZone(DateTimeZone.forTimeZone(TimeZone.getDefault())).toDate();
}
public Date getToTime() {
return transDate.plusDays(1).withZone(DateTimeZone.forTimeZone(TimeZone.getDefault())).toDate();
}
public TradeSecureFile addTransactions(List<JSONObject> transactions) {
tradeItems.addAll(transactions.stream().map(TradeItem::new).collect(Collectors.toList()));
return this;
}
public void writeToHttp(HttpServletResponse response) {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + filename());
try (OutputStream ous = response.getOutputStream()) {
ous.write(content());
ous.flush();
} catch (IOException e) {
throw new ServerErrorException(e);
}
}
public String filename() {
return String.join("_", transDate.toString("yyMMdd"), pid, createTime.toString("yyMMddHHmmss"));
}
public byte[] content() {
return content == null ? build() : content;
}
private byte[] build() {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(bos, StandardCharsets.UTF_8))) {
writer.println(headerLine());
for (TradeItem item : tradeItems) {
writer.println(item.line());
}
content = bos.toByteArray();
return content;
} catch (IOException e) {
throw new ServerErrorException(e);
}
}
private String headerLine() {
int totalCount = tradeItems.size();
BigDecimal totalCredit = tradeItems.stream().filter(TradeItem::isCredit).map(TradeItem::getClearingAmount)
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
BigDecimal totalDebit = tradeItems.stream().filter(TradeItem::isDebit).map(TradeItem::getClearingAmount)
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
String date = transDate.toString("yyyy-MM-dd");
String[] columns = {String.valueOf(totalCount), totalCredit.toPlainString(), totalDebit.toPlainString(), date, pid};
return String.join("|", columns);
}
class TradeItem {
private String clientMoniker;
private String orderId;
private String channel;
private TradeType gateway;
private BigDecimal price;
private BigDecimal clearingAmount;
private String currency;
private BigDecimal exchangeRate;
private String transactionType;
private Date transactionTime;
public TradeItem(JSONObject item) {
clientMoniker = item.getString("client_moniker");
transactionType = item.getString("transaction_type");
orderId = isCredit() ? item.getString("order_id") : item.getString("out_refund_id");
channel = item.getString("order_channel");
gateway = TradeType.fromGatewayNumber(item.getIntValue("gateway"));
currency = item.getString("transaction_currency");
price = CurrencyAmountUtils.scale(item.getBigDecimal("transaction_amount"), currency);
clearingAmount = CurrencyAmountUtils.scale(item.getBigDecimal("clearing_amount"), PlatformEnvironment.getEnv().getForeignCurrency());
exchangeRate = item.getBigDecimal("exchange_rate");
transactionTime = item.getDate("transaction_time");
}
public String line() {
String[] columns = {clientMoniker, orderId, channel, gateway.toString(), price.toPlainString(), clearingAmount.toPlainString(), currency,
exchangeRate.toPlainString(), filterStatus(), new DateTime(transactionTime).withZone(zone).toString()};
return String.join("|", columns);
}
private String filterStatus() {
return isCredit() ? "SUCCESS" : "REFUND";
}
public boolean isCredit() {
return "Credit".equals(transactionType);
}
public boolean isDebit() {
return "Debit".equals(transactionType);
}
public BigDecimal getClearingAmount() {
return clearingAmount;
}
}
}

@ -0,0 +1,94 @@
package au.com.royalpay.payment.manage.system.core.impl;
import au.com.royalpay.payment.core.exceptions.ChannelNetworkException;
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 com.alibaba.fastjson.JSONObject;
import com.jcraft.jsch.*;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.provider.sftp.SftpClientFactory;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.List;
/**
* Create by yixian at 2019-01-08 3:26
*/
@Service
public class TradeSecureServiceHanyinImpl implements TradeSecureService {
@Value("${app.hanyin-secure.pid:ROYALPAY}")
private String pid;
@Value("${app.hanyin-secure.sftp-host}")
private String sftpHost;
@Value("${app.hanyin-secure.sftp-port}")
private int sftpPort;
@Value("${app.hanyin-secure.sftp-username}")
private String sftpUsername;
@Value("${app.hanyin-secure.sftp-pwd}")
private String sftpPwd;
@Resource
private TransactionMapper transactionMapper;
@Override
public void uploadSecureReportYesterday() {
uploadSecureReport(DateTime.now().plusDays(-1).withMillisOfDay(0).toDate());
}
@Override
public void uploadSecureReport(Date date) {
TradeSecureFile file = getSecureReportFile(date);
sftpUpload(file);
}
private void sftpUpload(TradeSecureFile file) {
Session session = null;
ChannelSftp command = null;
try {
session = initSFTPConnection();
Channel channel = session.openChannel("sftp");
channel.connect();
command = (ChannelSftp) channel;
command.ls("/royalpay");
String dir = "/royalpay/" + file.getTransDate().toString("yyyyMMdd");
command.rmdir(dir);
command.mkdir(dir);
String dest = dir + file.filename();
command.put(new ByteArrayInputStream(file.content()), dest);
} catch (IOException | JSchException | SftpException e) {
throw new ChannelNetworkException("Upload Secure file failed", e);
} finally {
if (command != null && command.isConnected()) {
command.exit();
session.disconnect();
}
}
}
private Session initSFTPConnection() throws IOException {
FileSystemOptions fso = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso, "no");
return SftpClientFactory.createConnection(sftpHost, sftpPort,
sftpUsername.toCharArray(), sftpPwd.toCharArray(), fso);
}
@Override
public TradeSecureFile getSecureReportFile(Date date) {
TradeSecureFile file = new TradeSecureFile(pid, date);
Date from = file.getFromTime();
Date to = file.getToTime();
List<JSONObject> credits = transactionMapper.listCreditTransactionsForSecure(from, to);
file.addTransactions(credits);
List<JSONObject> debits = transactionMapper.listDebitTransactionsForSecure(from, to);
file.addTransactions(debits);
return file;
}
}

@ -0,0 +1,26 @@
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.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* Create by yixian at 2019-01-08 3:13
*/
@Component
@ConditionalOnProperty(value = "app.run-tasks", havingValue = "true")
public class SecureTask {
@Resource
private SynchronizedScheduler synchronizedScheduler;
@Resource
private TradeSecureService tradeSecureService;
@Scheduled(cron = "0 0 3 * * *")
public void pushSecureFile(){
synchronizedScheduler.executeProcess("task:secure_file_uploading",600_000,()->tradeSecureService.uploadSecureReportYesterday());
}
}

@ -133,3 +133,11 @@ settle.abafile.bank.ANZ.apca=514624
settle.abafile.bank.ANZ.bsb=013006 settle.abafile.bank.ANZ.bsb=013006
settle.abafile.bank.ANZ.account-no=837022519 settle.abafile.bank.ANZ.account-no=837022519
settle.abafile.bank.ANZ.account-name=Tunnel Show Pty Ltd settle.abafile.bank.ANZ.account-name=Tunnel Show Pty Ltd
# 瀚银Secure
app.hanyin-secure.pid=ROYALPAY
app.hanyin-secure.sftp-host=180.168.61.86
app.hanyin-secure.sftp-port=28480
app.hanyin-secure.sftp-username=royalpay
app.hanyin-secure.sftp-pwd=royalpay

@ -4,13 +4,19 @@
<update id="removeSettleRemark"> <update id="removeSettleRemark">
UPDATE pmt_transactions AS t UPDATE pmt_transactions AS t
INNER JOIN log_clearing_detail d ON d.clear_detail_id = t.clearing_order INNER JOIN log_clearing_detail d ON d.clear_detail_id = t.clearing_order
SET clearing_status = 0, clearing_order = NULL, clearing_time = NULL SET clearing_status = 0,
clearing_order = NULL,
clearing_time = NULL
WHERE d.clearing_id = #{clearing_id} WHERE d.clearing_id = #{clearing_id}
</update> </update>
<delete id="deleteSettlementTransaction"> <delete id="deleteSettlementTransaction">
DELETE t FROM pmt_transactions t DELETE t
INNER JOIN log_clearing_detail d ON d.clear_detail_id = t.clearing_order FROM pmt_transactions t
WHERE d.clearing_id = #{clearing_id} AND t.transaction_type = 'Debit' AND t.refund_id IS NULL and t.channel='Settlement' INNER JOIN log_clearing_detail d ON d.clear_detail_id = t.clearing_order
WHERE d.clearing_id = #{clearing_id}
AND t.transaction_type = 'Debit'
AND t.refund_id IS NULL
and t.channel = 'Settlement'
</delete> </delete>
<select id="listTransFlowPage" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransFlowPage" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.*,if(t.refund_id is not null,'refund',if(t.transaction_type='Debit' AND SELECT t.*,if(t.refund_id is not null,'refund',if(t.transaction_type='Debit' AND
@ -95,7 +101,7 @@
THEN 'Native QR Code' THEN 'Native QR Code'
WHEN 14 WHEN 14
THEN 'Share Link' THEN 'Share Link'
END AS gateway, END AS gateway,
CASE o.channel CASE o.channel
WHEN 'Alipay' THEN ra.login_id WHEN 'Alipay' THEN ra.login_id
WHEN 'AlipayOnline' THEN ra.login_email WHEN 'AlipayOnline' THEN ra.login_email
@ -217,14 +223,16 @@
<select id="findLastIncome" resultType="com.alibaba.fastjson.JSONObject"> <select id="findLastIncome" resultType="com.alibaba.fastjson.JSONObject">
SELECT * SELECT *
FROM pmt_transactions FROM pmt_transactions
WHERE channel = 'Wechat' AND transaction_type = 'Credit' WHERE channel = 'Wechat'
AND transaction_type = 'Credit'
ORDER BY transaction_time DESC ORDER BY transaction_time DESC
LIMIT 1 LIMIT 1
</select> </select>
<select id="getClientUnClearedAmount" resultType="java.lang.Double"> <select id="getClientUnClearedAmount" resultType="java.lang.Double">
SELECT ifnull(sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)), 0) SELECT ifnull(sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)), 0)
FROM pmt_transactions FROM pmt_transactions
WHERE clearing_status = 0 AND client_id = #{client_id} WHERE clearing_status = 0
AND client_id = #{client_id}
</select> </select>
<select id="getClientsUnClearedAmount" resultType="com.alibaba.fastjson.JSONObject"> <select id="getClientsUnClearedAmount" resultType="com.alibaba.fastjson.JSONObject">
@ -252,14 +260,13 @@
</select> </select>
<select id="listPreRefundClients" resultType="com.alibaba.fastjson.JSONObject"> <select id="listPreRefundClients" resultType="com.alibaba.fastjson.JSONObject">
SELECT * SELECT *
FROM (SELECT FROM (SELECT ifnull(sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)), 0) amount,
ifnull(sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)), 0) amount, c.client_id client_id,
c.client_id client_id, max(t.transaction_time) transation_time,
max(t.transaction_time) transation_time, c.client_moniker client_moniker
c.client_moniker client_moniker
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN sys_clients c ON t.client_id = c.client_id INNER JOIN sys_clients c ON t.client_id = c.client_id
INNER JOIN sys_client_config cc on cc.client_id = c.client_id AND cc.enable_refund_auth = 1 INNER JOIN sys_client_config cc on cc.client_id = c.client_id AND cc.enable_refund_auth = 1
GROUP BY c.client_id) a GROUP BY c.client_id) a
WHERE a.amount &lt; 0 WHERE a.amount &lt; 0
</select> </select>
@ -281,41 +288,38 @@
</select> </select>
<select id="listUnclearedTransactionsOfClient" resultType="com.alibaba.fastjson.JSONObject"> <select id="listUnclearedTransactionsOfClient" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT c.client_id,
c.client_moniker,
SELECT c.parent_client_id,
c.client_id, c.org_id,
c.client_moniker, cc.clean_days,
c.parent_client_id, t.transaction_id,
c.org_id, t.transaction_type,
cc.clean_days, t.transaction_time,
t.transaction_id, t.clearing_amount,
t.transaction_type, t.channel,
t.transaction_time, t.system_generate,
t.clearing_amount, t.order_id,
t.channel, t.refund_id,
t.system_generate, t.cny_amount,
t.order_id, t.exchange_rate,
t.refund_id, o.display_amount,
t.cny_amount, o.total_amount
t.exchange_rate,
o.display_amount,
o.total_amount
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN sys_clients c ON c.client_id = t.client_id INNER JOIN sys_clients c ON c.client_id = t.client_id
inner join sys_client_config cc on cc.client_id = c.client_id inner join sys_client_config cc on cc.client_id = c.client_id
LEFT JOIN pmt_orders o ON o.order_id = t.order_id LEFT JOIN pmt_orders o ON o.order_id = t.order_id
WHERE t.clearing_order IS NULL AND t.clearing_status = 0 AND t.channel != 'Settlement' AND WHERE t.clearing_order IS NULL
t.client_id = #{client_id} AND AND t.clearing_status = 0
((t.transaction_type = 'Credit' AND t.transaction_time < #{end} AND t.channel != 'System') AND t.channel != 'Settlement'
OR (t.transaction_type = 'Credit' AND date(t.transaction_time) < date(#{settleDate}) AND AND t.client_id = #{client_id}
t.channel = 'System') AND ((t.transaction_type = 'Credit' AND t.transaction_time < #{end} AND t.channel != 'System')
OR (t.transaction_type = 'Debit' AND t.transaction_time < now()) OR (t.transaction_type = 'Credit' AND date(t.transaction_time) < date(#{settleDate}) AND
) t.channel = 'System')
OR (t.transaction_type = 'Debit' AND t.transaction_time < now())
)
GROUP BY t.transaction_id GROUP BY t.transaction_id
ORDER BY t.transaction_type, t.transaction_time ORDER BY t.transaction_type, t.transaction_time
]]> ]]>
</select> </select>
@ -461,77 +465,66 @@
<select id="getMerchantAmount" resultType="com.alibaba.fastjson.JSONObject"> <select id="getMerchantAmount" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT temp.* SELECT temp.*
FROM ( FROM (
SELECT SELECT #{clearing_date} AS order_time,
#{clearing_date} AS order_time, #{clearing_date} AS clearing_time,
#{clearing_date} AS clearing_time, t.client_id,
t.client_id, round(sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) *
round(sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) * (100 - ifnull(min(r.rate_value), 1.4))) / 100 clearing_amount,
(100 - ifnull(min(r.rate_value), 1.4))) / 100 clearing_amount, t.transaction_currency currency,
t.transaction_currency currency, t.order_id
t.order_id
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN sys_client_config c ON t.client_id = c.client_id AND c.skip_clearing = 0 INNER JOIN sys_client_config c ON t.client_id = c.client_id AND c.skip_clearing = 0
LEFT JOIN sys_client_rates r ON r.client_id = t.client_id LEFT JOIN sys_client_rates r ON r.client_id = t.client_id
AND date(r.expiry_time) >= DATE(t.transaction_time) AND date(r.expiry_time) >= DATE(t.transaction_time)
AND date(r.active_time) <= DATE(t.transaction_time) AND date(r.active_time) <= DATE(t.transaction_time)
INNER JOIN sys_bank_accounts a ON a.client_id = t.client_id INNER JOIN sys_bank_accounts a ON a.client_id = t.client_id
WHERE WHERE t.transaction_time >= #{from}
t.transaction_time >= #{from} AND t.transaction_time < #{to} AND t.channel != 'Settlement' AND t.transaction_time < #{to}
AND t.channel != 'Settlement'
GROUP BY t.client_id) temp GROUP BY t.client_id) temp
WHERE clearing_amount != 0 WHERE clearing_amount != 0
]]> ]]>
</select> </select>
<select id="getSumMerchantAmount" resultType="com.alibaba.fastjson.JSONObject"> <select id="getSumMerchantAmount" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT SUM(temp.clearing_amount) clearing_amount SELECT SUM(temp.clearing_amount) clearing_amount
FROM FROM (SELECT round(sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) *
(SELECT round(sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) * (100 - ifnull(min(r.rate_value), 1.6))) / 100 clearing_amount
(100 - ifnull(min(r.rate_value), 1.6))) / 100 clearing_amount FROM pmt_transactions t
FROM pmt_transactions t INNER JOIN sys_client_config c ON t.client_id = c.client_id AND c.skip_clearing = 0
INNER JOIN sys_client_config c ON t.client_id = c.client_id AND c.skip_clearing = 0 LEFT JOIN sys_client_rates r ON r.client_id = t.client_id
LEFT JOIN sys_client_rates r ON r.client_id = t.client_id AND date(r.expiry_time) >= DATE(t.transaction_time)
AND date(r.expiry_time) >= DATE(t.transaction_time) AND date(r.active_time) <= DATE(t.transaction_time)
AND date(r.active_time) <= DATE(t.transaction_time) INNER JOIN sys_bank_accounts a ON a.client_id = t.client_id
INNER JOIN sys_bank_accounts a ON a.client_id = t.client_id WHERE t.transaction_time >= #{from}
WHERE AND t.transaction_time < #{to}
t.transaction_time >= #{from} AND t.transaction_time < #{to} AND t.channel != 'Settlement' AND t.channel != 'Settlement'
GROUP BY t.client_id) temp GROUP BY t.client_id) temp
WHERE temp.clearing_amount != 0 WHERE temp.clearing_amount != 0
]]> ]]>
</select> </select>
<select id="analysisTotalTransactions" resultType="java.lang.Double"> <select id="analysisTotalTransactions" resultType="java.lang.Double">
<![CDATA[ <![CDATA[
SELECT ifnull(sum(clearing_amount), 0) total SELECT ifnull(sum(clearing_amount), 0) total
FROM pmt_transactions FROM pmt_transactions
WHERE client_id = #{client_id} AND date(transaction_time) >= date(#{begin}) AND WHERE client_id = #{client_id}
date(transaction_time) <= date(#{end}) AND date(transaction_time) >= date(#{begin})
AND date(transaction_time) <= date(#{end})
]]> ]]>
</select> </select>
<select id="listTransactionsOfClearingTask" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionsOfClearingTask" resultType="com.alibaba.fastjson.JSONObject">
SELECT SELECT t.*,
t.*, cl.client_moniker
cl.client_moniker
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN log_clearing_detail d ON d.clear_detail_id = t.clearing_order INNER JOIN log_clearing_detail d ON d.clear_detail_id = t.clearing_order
INNER JOIN log_clearing c ON c.clearing_id = d.clearing_id AND c.clearing_id = #{clear_id} INNER JOIN log_clearing c ON c.clearing_id = d.clearing_id AND c.clearing_id = #{clear_id}
INNER JOIN sys_clients cl ON cl.client_id = t.client_id INNER JOIN sys_clients cl ON cl.client_id = t.client_id
inner join sys_client_config cc on cc.clear_id = cl.client_id and cc.is_valid = 1 inner join sys_client_config cc on cc.clear_id = cl.client_id and cc.is_valid = 1
WHERE t.transaction_type = 'Credit' OR t.refund_id IS NOT NULL WHERE t.transaction_type = 'Credit'
OR t.refund_id IS NOT NULL
ORDER BY t.order_id ASC ORDER BY t.order_id ASC
</select> </select>
@ -560,259 +553,267 @@
<select id="TotalAmountForBDPrize" resultType="java.math.BigDecimal"> <select id="TotalAmountForBDPrize" resultType="java.math.BigDecimal">
<![CDATA[ <![CDATA[
select sum(if(temp.transaction_type = 'Credit', temp.clearing_amount * d.proportion,
-temp.clearing_amount * d.proportion))
select sum(if(temp.transaction_type='Credit',temp.clearing_amount*d.proportion,-temp.clearing_amount*d.proportion)) total
total FROM FROM (SELECT l.client_id,l.clearing_amount,l.refund_id,l.transaction_type,o.create_time
(SELECT l.client_id,l.clearing_amount,l.refund_id,l.transaction_type,o.create_time FROM pmt_transactions l FROM pmt_transactions l
INNER JOIN pmt_orders o INNER JOIN pmt_orders o
ON o.order_id = l.order_id ON o.order_id = l.order_id
and year(o.create_time) = #{year} AND month(o.create_time) = #{month} and year(o.create_time) = #{year} AND month(o.create_time) = #{month}
where (l.transaction_type='Credit' or l.refund_id is not null) where (l.transaction_type = 'Credit' or l.refund_id is not null)
) temp ) temp
INNER JOIN sys_client_bd d ON temp.client_id = d.client_id AND d.start_date <= temp.create_time and INNER JOIN sys_client_bd d ON temp.client_id = d.client_id AND d.start_date <= temp.create_time and
d.is_valid = '1' d.is_valid = '1'
AND (d.end_date is null or d.end_date > temp.create_time) AND (d.end_date is null or d.end_date > temp.create_time)
and d.bd_id=#{bd_id} and d.bd_id = #{bd_id}
]]> ]]>
</select> </select>
<select id="TotalAmountForBDLeaderPrize" resultType="java.math.BigDecimal"> <select id="TotalAmountForBDLeaderPrize" resultType="java.math.BigDecimal">
SELECT SELECT ifnull(sum(t.total), 0)
ifnull(sum(t.total),0) total
total
FROM statistics_customer_order t FROM statistics_customer_order t
INNER JOIN sys_clients c ON c.client_id = t.client_id AND c.org_id = 1 INNER JOIN sys_clients c ON c.client_id = t.client_id AND c.org_id = 1
WHERE year(t.date) = #{year} AND month(t.date) = #{month} WHERE year(t.date) = #{year}
and t.client_id!=0 AND month(t.date) = #{month}
and t.client_id in and t.client_id != 0
(SELECT b.client_id FROM sys_client_bd b and t.client_id in
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id (SELECT b.client_id
where b.is_valid=1 and b.start_date&lt;=now() and (b.end_date is null or b.end_date &gt;= now()) FROM sys_client_bd b
AND c.bd_group=#{bd_group} or c.manager_id=#{bd_group}) INNER JOIN financial_bd_config c ON c.manager_id = b.bd_id
where b.is_valid = 1 and b.start_date &lt;= now() and (b.end_date is null or b.end_date &gt;= now())
AND c.bd_group = #{bd_group}
or c.manager_id = #{bd_group})
</select> </select>
<select id="TotalAmountForSydneyGMPrize" resultType="java.math.BigDecimal"> <select id="TotalAmountForSydneyGMPrize" resultType="java.math.BigDecimal">
SELECT SELECT ifnull(sum(t.total), 0)
ifnull(sum(t.total),0) total
total
FROM statistics_customer_order t FROM statistics_customer_order t
INNER JOIN sys_clients c ON c.client_id = t.client_id AND c.org_id = 1 INNER JOIN sys_clients c ON c.client_id = t.client_id AND c.org_id = 1
WHERE year(t.date) = #{year} AND month(t.date) = #{month} WHERE year(t.date) = #{year}
and t.client_id!=0 AND month(t.date) = #{month}
and t.client_id in and t.client_id != 0
(SELECT b.client_id FROM sys_client_bd b and t.client_id in
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id (SELECT b.client_id
where b.is_valid=1 and b.start_date&lt;=now() and (b.end_date is null or b.end_date &gt;= now()) FROM sys_client_bd b
AND c.city='Sydney') INNER JOIN financial_bd_config c ON c.manager_id = b.bd_id
where b.is_valid = 1
and b.start_date &lt;= now()
and (b.end_date is null or b.end_date &gt;= now())
AND c.city = 'Sydney')
</select> </select>
<select id="listTransactionsForCityPartnerCommission" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionsForCityPartnerCommission" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) * b.proportion
total,
SELECT t.client_id,
sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) * b.proportion m.org_id,
total, c.approve_time client_create_time,
t.client_id, c.source client_source,
m.org_id, date(t.transaction_time) trade_date,
c.approve_time client_create_time, t.channel channel,
c.source client_source, ifnull((SELECT min(r.rate_value)
date(t.transaction_time) trade_date, FROM sys_client_rates r
t.channel channel, WHERE r.client_id = t.client_id
ifnull((SELECT min(r.rate_value) AND r.active_time <= t.transaction_time
FROM sys_client_rates r AND r.expiry_time >= t.transaction_time
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND AND r.rate_name = 'Wechat'), 1) wechat_rate_value,
r.expiry_time >= t.transaction_time AND ifnull((SELECT min(r.rate_value)
r.rate_name = 'Wechat'), 1) wechat_rate_value, FROM sys_client_rates r
ifnull((SELECT min(r.rate_value) WHERE r.client_id = t.client_id
FROM sys_client_rates r AND r.active_time <= t.transaction_time
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND AND r.expiry_time >= t.transaction_time
r.expiry_time >= t.transaction_time AND AND r.rate_name = 'Alipay'), 1) alipay_rate_value,
r.rate_name = 'Alipay'), 1) alipay_rate_value, ifnull((SELECT min(r.rate_value)
ifnull((SELECT min(r.rate_value) FROM sys_client_rates r
FROM sys_client_rates r WHERE r.client_id = t.client_id
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND AND r.active_time <= t.transaction_time
r.expiry_time >= t.transaction_time AND AND r.expiry_time >= t.transaction_time
r.rate_name = 'Bestpay'), 1) bestpay_rate_value, AND r.rate_name = 'Bestpay'), 1) bestpay_rate_value,
ifnull((SELECT min(r.rate_value) ifnull((SELECT min(r.rate_value)
FROM sys_client_rates r FROM sys_client_rates r
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND WHERE r.client_id = t.client_id
r.expiry_time >= t.transaction_time AND AND r.active_time <= t.transaction_time
r.rate_name = 'jd'), 1) jd_rate_value, AND r.expiry_time >= t.transaction_time
ifnull((SELECT min(r.rate_value) AND r.rate_name = 'jd'), 1) jd_rate_value,
FROM sys_client_rates r ifnull((SELECT min(r.rate_value)
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND FROM sys_client_rates r
r.expiry_time >= t.transaction_time AND WHERE r.client_id = t.client_id
r.rate_name = 'AlipayOnline'), 2.0) AlipayOnline_rate_value AND r.active_time <= t.transaction_time
AND r.expiry_time >= t.transaction_time
AND r.rate_name = 'AlipayOnline'), 2.0) AlipayOnline_rate_value
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN sys_clients c ON c.client_id = t.client_id INNER JOIN sys_clients c ON c.client_id = t.client_id
INNER JOIN sys_client_bd b ON b.client_id = c.client_id AND b.start_date <= t.transaction_time INNER JOIN sys_client_bd b ON b.client_id = c.client_id AND b.start_date <= t.transaction_time
AND (b.end_date IS NULL OR b.end_date >= t.transaction_time) AND AND (b.end_date IS NULL OR b.end_date >= t.transaction_time) AND
b.is_valid = 1 b.is_valid = 1
INNER JOIN sys_managers m ON m.manager_id = b.bd_id INNER JOIN sys_managers m ON m.manager_id = b.bd_id
INNER JOIN sys_org so INNER JOIN sys_org so
ON m.org_id = so.org_id AND so.is_valid = 1 AND so.type = 0 AND so.citypartner = 1 AND so.commission = 1 ON m.org_id = so.org_id AND so.is_valid = 1 AND so.type = 0 AND so.citypartner = 1 AND
WHERE year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} AND t.channel != 'Settlement' so.commission = 1
WHERE year(t.transaction_time) = #{year}
AND month(t.transaction_time) = #{month}
AND t.channel != 'Settlement'
GROUP BY t.client_id, trade_date, channel GROUP BY t.client_id, trade_date, channel
ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC
]]> ]]>
</select> </select>
<select id="listTransactionForCityPartnerCommissionByDate" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionForCityPartnerCommissionByDate" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
select t.org_id,t.clearing_currency,t.client_id,t.channel,t.surcharge_rate,t.transaction_time,if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount) clearing_amount, select t.org_id,
if(t.transaction_type = 'Credit', t.total_surcharge, -t.total_surcharge) total_surcharge, t.clearing_currency,
if(t.transaction_type = 'Credit', t.channel_surcharge, -t.channel_surcharge) channel_surcharge, t.client_id,
t.order_id t.channel,
from pmt_transactions t INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1 t.surcharge_rate,
AND so.type=0 t.transaction_time,
AND so.citypartner = 1 AND so.commission = 1 if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount) clearing_amount,
AND year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} if(t.transaction_type = 'Credit', t.total_surcharge, -t.total_surcharge) total_surcharge,
AND t.channel != 'Settlement' AND t.channel!='System' if(t.transaction_type = 'Credit', t.channel_surcharge, -t.channel_surcharge) channel_surcharge,
t.order_id
from pmt_transactions t
INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1
AND so.type = 0
AND so.citypartner = 1 AND so.commission = 1
AND year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month}
AND t.channel != 'Settlement' AND t.channel != 'System'
ORDER BY t.client_id asc ORDER BY t.client_id asc
]]> ]]>
</select> </select>
<select id="listTransactionForCityPartnerAgentCommissionByDate" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionForCityPartnerAgentCommissionByDate" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
select t.org_id,t.client_id,t.channel,t.surcharge_rate,t.transaction_time,if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount) clearing_amount, select t.org_id,
if(t.transaction_type = 'Credit', t.total_surcharge, -t.total_surcharge) total_surcharge, t.client_id,
if(t.transaction_type = 'Credit', t.channel_surcharge, -t.channel_surcharge) channel_surcharge, t.channel,
t.order_id t.surcharge_rate,
from pmt_transactions t INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1 t.transaction_time,
AND so.type=0 if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount) clearing_amount,
AND so.parent_org_id !='' if(t.transaction_type = 'Credit', t.total_surcharge, -t.total_surcharge) total_surcharge,
AND so.citypartner = 1 AND so.commission = 1 if(t.transaction_type = 'Credit', t.channel_surcharge, -t.channel_surcharge) channel_surcharge,
AND year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} t.order_id
AND t.channel != 'Settlement' AND t.channel!='System' from pmt_transactions t
INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1
AND so.type = 0
AND so.parent_org_id != ''
AND so.citypartner = 1 AND so.commission = 1
AND year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month}
AND t.channel != 'Settlement' AND t.channel != 'System'
ORDER BY t.client_id asc ORDER BY t.client_id asc
]]> ]]>
</select> </select>
<select id="listTransactionsForReferrerCommission" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionsForReferrerCommission" resultType="com.alibaba.fastjson.JSONObject">
SELECT SELECT sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount))
sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) total,
total, t.client_id client_id,
t.client_id client_id, so.org_id org_id,
so.org_id org_id, c.source client_source,
c.source client_source, date(t.transaction_time) trade_date,
date(t.transaction_time) trade_date, ifnull(so.rate_value, 1) rate_value
ifnull(so.rate_value, 1) rate_value
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN sys_clients c ON c.client_id = t.client_id INNER JOIN sys_clients c ON c.client_id = t.client_id
inner join sys_client_config cc on cc.client_id = c.client_id inner join sys_client_config cc on cc.client_id = c.client_id
INNER JOIN sys_org so INNER JOIN sys_org so
ON c.referrer_id = so.org_id AND so.is_valid = 1 AND so.type = 1 AND so.commission = 1 ON c.referrer_id = so.org_id AND so.is_valid = 1 AND so.type = 1 AND so.commission = 1
WHERE year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} AND t.channel != 'Settlement' WHERE year(t.transaction_time) = #{year}
AND month(t.transaction_time) = #{month}
AND t.channel != 'Settlement'
GROUP BY so.org_id, trade_date, t.client_id GROUP BY so.org_id, trade_date, t.client_id
ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC
</select> </select>
<select id="listTransactionsForAgentCommission" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionsForAgentCommission" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount))
total,
SELECT t.client_id client_id,
sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) c.approve_time client_create_time,
total, c.source client_source,
t.client_id client_id, date(t.transaction_time) trade_date,
c.approve_time client_create_time, t.channel channel,
c.source client_source, ifnull(so.rate_value, 1) rate_value,
date(t.transaction_time) trade_date, ifnull((SELECT min(r.rate_value)
t.channel channel, FROM sys_client_rates r
ifnull(so.rate_value, 1) rate_value, WHERE r.client_id = t.client_id
ifnull((SELECT min(r.rate_value) AND r.active_time <= t.transaction_time
FROM sys_client_rates r AND r.expiry_time >= t.transaction_time
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND AND r.rate_name = 'Wechat'), 1) wechat_rate_value,
r.expiry_time >= t.transaction_time AND ifnull((SELECT min(r.rate_value)
r.rate_name = 'Wechat'), 1) wechat_rate_value, FROM sys_client_rates r
ifnull((SELECT min(r.rate_value) WHERE r.client_id = t.client_id
FROM sys_client_rates r AND r.active_time <= t.transaction_time
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND AND r.expiry_time >= t.transaction_time
r.expiry_time >= t.transaction_time AND AND r.rate_name = 'Alipay'), 1) alipay_rate_value,
r.rate_name = 'Alipay'), 1) alipay_rate_value, ifnull((SELECT min(r.rate_value)
ifnull((SELECT min(r.rate_value) FROM sys_client_rates r
FROM sys_client_rates r WHERE r.client_id = t.client_id
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND AND r.active_time <= t.transaction_time
r.expiry_time >= t.transaction_time AND AND r.expiry_time >= t.transaction_time
r.rate_name = 'Bestpay'), 1) bestpay_rate_value, AND r.rate_name = 'Bestpay'), 1) bestpay_rate_value,
ifnull((SELECT min(r.rate_value) ifnull((SELECT min(r.rate_value)
FROM sys_client_rates r FROM sys_client_rates r
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND WHERE r.client_id = t.client_id
r.expiry_time >= t.transaction_time AND AND r.active_time <= t.transaction_time
r.rate_name = 'jd'), 1) jd_rate_value, AND r.expiry_time >= t.transaction_time
ifnull((SELECT min(r.rate_value) AND r.rate_name = 'jd'), 1) jd_rate_value,
FROM sys_client_rates r ifnull((SELECT min(r.rate_value)
WHERE r.client_id = t.client_id AND r.active_time <= t.transaction_time AND FROM sys_client_rates r
r.expiry_time >= t.transaction_time AND WHERE r.client_id = t.client_id
r.rate_name = 'AlipayOnline'), 2.0) AlipayOnline_rate_value AND r.active_time <= t.transaction_time
AND r.expiry_time >= t.transaction_time
AND r.rate_name = 'AlipayOnline'), 2.0) AlipayOnline_rate_value
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN sys_clients c ON c.client_id = t.client_id INNER JOIN sys_clients c ON c.client_id = t.client_id
INNER JOIN sys_org so INNER JOIN sys_org so
ON c.org_id = so.org_id AND so.is_valid = 1 AND so.type = 0 AND so.parent_org_id = #{parent_org_id} ON c.org_id = so.org_id AND so.is_valid = 1 AND so.type = 0 AND so.parent_org_id = #{parent_org_id}
WHERE year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} AND t.channel != 'Settlement' WHERE year(t.transaction_time) = #{year}
AND month(t.transaction_time) = #{month}
AND t.channel != 'Settlement'
GROUP BY t.client_id, trade_date, channel GROUP BY t.client_id, trade_date, channel
ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC
]]> ]]>
</select> </select>
<select id="checkBalance" resultType="java.math.BigDecimal"> <select id="checkBalance" resultType="java.math.BigDecimal">
<![CDATA[ <![CDATA[
SELECT sum(subval) SELECT sum(subval)
FROM (SELECT FROM (SELECT c.client_moniker,
c.client_moniker, a.client_id,
a.client_id, a.total_credit,
a.total_credit, a.total_debit,
a.total_debit, a.total_debit - a.total_credit subval
a.total_debit - a.total_credit subval FROM (
FROM SELECT sum(
( IF(
SELECT t.transaction_type = 'Credit',
sum( t.clearing_amount,
0
IF( )
t.transaction_type = 'Credit', ) total_credit,
t.clearing_amount, sum(
0 IF(
) t.transaction_type = 'Debit',
) total_credit, t.clearing_amount,
sum( 0
)
IF( ) total_debit,
t.transaction_type = 'Debit', t.client_id
t.clearing_amount, FROM pmt_transactions t
0 WHERE t.clearing_status = 1
) AND (date(t.clearing_time) <= date(#{end}) OR t.clearing_time IS NULL)
) total_debit, GROUP BY t.client_id
t.client_id ) a
FROM INNER JOIN sys_clients c ON c.client_id = a.client_id
pmt_transactions t AND c.client_id != 9
WHERE AND (
t.clearing_status = 1 c.parent_client_id != 9
AND (date(t.clearing_time) <= date(#{end}) OR t.clearing_time IS NULL) OR c.parent_client_id IS NULL
GROUP BY )
t.client_id WHERE abs(total_credit - total_debit) > 1
) a ORDER BY subval DESC) t
INNER JOIN sys_clients c ON c.client_id = a.client_id
AND c.client_id != 9
AND (
c.parent_client_id != 9
OR c.parent_client_id IS NULL
)
WHERE
abs(total_credit - total_debit) > 1
ORDER BY
subval DESC) t
]]> ]]>
</select> </select>
<select id="listDailyTransactions" resultType="com.alibaba.fastjson.JSONObject"> <select id="listDailyTransactions" resultType="com.alibaba.fastjson.JSONObject">
@ -866,37 +867,35 @@ select sum(if(temp.transaction_type='Credit',temp.clearing_amount*d.proportion,
</select> </select>
<select id="listTransactionsOfClearingOrder" resultType="com.alibaba.fastjson.JSONObject"> <select id="listTransactionsOfClearingOrder" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT t.*,
o.display_amount,
SELECT o.client_order_id,
t.*, o.gateway,
o.display_amount, r.out_refund_id,
o.client_order_id, r.client_refund_id,
o.gateway, o.order_detail,
r.out_refund_id, o.dev_id
r.client_refund_id,
o.order_detail,
o.dev_id
FROM pmt_transactions t FROM pmt_transactions t
LEFT JOIN pmt_orders o ON o.order_id = t.order_id LEFT JOIN pmt_orders o ON o.order_id = t.order_id
LEFT JOIN pmt_refunds r ON r.refund_id = t.refund_id LEFT JOIN pmt_refunds r ON r.refund_id = t.refund_id
WHERE t.channel != 'Settlement' AND t.clearing_order = #{clearing_order} WHERE t.channel != 'Settlement'
AND t.clearing_order = #{clearing_order}
]]> ]]>
</select> </select>
<select id="listSettlementTransactions" resultType="com.alibaba.fastjson.JSONObject"> <select id="listSettlementTransactions" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.* SELECT t.*
FROM pmt_transactions t FROM pmt_transactions t
WHERE t.channel = 'Settlement' AND t.clearing_order = #{clearing_order} WHERE t.channel = 'Settlement'
AND t.clearing_order = #{clearing_order}
</select> </select>
<select id="analysisCustomerPaid" resultType="java.math.BigDecimal"> <select id="analysisCustomerPaid" resultType="java.math.BigDecimal">
SELECT ifnull(sum(t.clearing_amount), 0) SELECT ifnull(sum(t.clearing_amount), 0)
FROM pmt_transactions t FROM pmt_transactions t
INNER JOIN pmt_orders o INNER JOIN pmt_orders o
ON o.order_id = t.order_id AND o.transaction_date BETWEEN #{startDate} AND #{endDate} AND ON o.order_id = t.order_id AND o.transaction_date BETWEEN #{startDate} AND #{endDate} AND
o.customer_id = #{customer_id} o.customer_id = #{customer_id}
WHERE t.system_generate = 0 AND t.transaction_type = 'Credit' WHERE t.system_generate = 0
AND t.transaction_type = 'Credit'
</select> </select>
<select id="getSettleDelayAnalysis" resultType="com.alibaba.fastjson.JSONObject"> <select id="getSettleDelayAnalysis" resultType="com.alibaba.fastjson.JSONObject">
@ -951,41 +950,86 @@ select sum(if(temp.transaction_type='Credit',temp.clearing_amount*d.proportion,
group by client_id group by client_id
</select> </select>
<select id="listClientUnsettleDataByDate" resultType="com.alibaba.fastjson.JSONObject"> <select id="listClientUnsettleDataByDate" resultType="com.alibaba.fastjson.JSONObject">
SELECT SELECT date(transaction_time) trans_date,
date(transaction_time) trans_date, sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)) clearing_amount,
sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)) clearing_amount, sum(if(transaction_type = 'Credit', settle_amount, -settle_amount)) settle_amount
sum(if(transaction_type = 'Credit', settle_amount, -settle_amount)) settle_amount
FROM pmt_transactions t FROM pmt_transactions t
WHERE t.client_id = #{client_id} AND t.clearing_status = 0 AND date(t.transaction_time)&lt;=date(#{max_settle_to}) WHERE t.client_id = #{client_id}
AND t.clearing_status = 0
AND date(t.transaction_time) &lt;= date(#{max_settle_to})
GROUP BY trans_date GROUP BY trans_date
ORDER BY trans_date DESC ORDER BY trans_date DESC
</select> </select>
<select id="getHfClearAmount" resultType="com.alibaba.fastjson.JSONObject"> <select id="getHfClearAmount" resultType="com.alibaba.fastjson.JSONObject">
SELECT sum(clearing_amount) clear_amount, SELECT sum(clearing_amount) clear_amount,
sum(channel_surcharge) charge_amount , sum(channel_surcharge) charge_amount,
transaction_type transaction_type
FROM pmt_transactions where channel='hf' FROM pmt_transactions
AND transaction_time >= #{datefrom} where channel = 'hf'
AND transaction_time &lt;= #{dateto} AND transaction_time >= #{datefrom}
GROUP BY transaction_type AND transaction_time &lt;= #{dateto}
GROUP BY transaction_type
</select> </select>
<select id="analysisForATOReport" resultType="com.alibaba.fastjson.JSONObject"> <select id="analysisForATOReport" resultType="com.alibaba.fastjson.JSONObject">
select sum(if(transaction_type='Credit',t.clearing_amount,0)) gross_payment, select sum(if(transaction_type = 'Credit', t.clearing_amount, 0)) gross_payment,
sum(if(transaction_type='Credit',1,0)) pay_count, sum(if(transaction_type = 'Credit', 1, 0)) pay_count,
sum(if(transaction_type='Debit',t.clearing_amount,0)) total_refund, sum(if(transaction_type = 'Debit', t.clearing_amount, 0)) total_refund,
sum(if(transaction_type='Debit',1,0)) refund_count, sum(if(transaction_type = 'Debit', 1, 0)) refund_count,
min(t.transaction_time) period_start, min(t.transaction_time) period_start,
max(t.transaction_time) period_end, max(t.transaction_time) period_end,
cd.bsb_no, cd.bsb_no,
cd.account_no, cd.account_no,
cd.account_name cd.account_name
from pmt_transactions t from pmt_transactions t
inner join log_clearing_detail cd on cd.clear_detail_id=t.clearing_order inner join log_clearing_detail cd on cd.clear_detail_id = t.clearing_order
where t.client_id=#{clientId} and t.system_generate=0 and t.clearing_status=1 and t.transaction_time between #{from} and #{to} where t.client_id = #{clientId}
and t.channel!='Settlement' and t.system_generate = 0
and t.clearing_status = 1
and t.transaction_time between #{from} and #{to}
and t.channel != 'Settlement'
group by cd.bsb_no,cd.account_no group by cd.bsb_no,cd.account_no
order by period_start order by period_start
</select> </select>
<select id="listCreditTransactionsForSecure" resultType="com.alibaba.fastjson.JSONObject">
select c.client_moniker,
o.order_id,
o.gateway,
t.transaction_amount,
t.transaction_currency,
t.order_channel,
t.clearing_amount,
t.exchange_rate,
t.transaction_time,
t.transaction_type
from pmt_transactions t
inner join pmt_orders o on o.order_id = t.order_id
inner join sys_clients c on c.client_id = t.client_id
where t.transaction_time between #{from} and #{to}
and t.channel not in ('Settlement', 'System')
and t.system_generate = 0
and t.transaction_type = 'Credit'
</select>
<select id="listDebitTransactionsForSecure" resultType="com.alibaba.fastjson.JSONObject">
select c.client_moniker,
o.order_id,
o.gateway,
r.out_refund_id,
t.transaction_amount,
t.transaction_currency,
t.order_channel,
t.clearing_amount,
t.exchange_rate,
t.transaction_time,
t.transaction_type
from pmt_transactions t
inner join pmt_orders o on o.order_id = t.order_id
inner join sys_clients c on c.client_id = t.client_id
inner join pmt_refunds r on r.refund_id = t.refund_id
where t.transaction_time between #{from} and #{to}
and t.channel not in ('Settlement', 'System')
and t.system_generate = 0
and t.transaction_type = 'Debit'
</select>
</mapper> </mapper>

Loading…
Cancel
Save