master
yixian 7 years ago
parent 4550ed0958
commit d98624f2ce

@ -10,15 +10,12 @@ import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.core.exceptions.OrderNotMatchException;
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
import au.com.royalpay.payment.manage.mappers.client.ClientCustomersMapper;
import au.com.royalpay.payment.manage.mappers.payment.AustracDataMapper;
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
import au.com.royalpay.payment.manage.mappers.payment.RefundAuditionMapper;
import au.com.royalpay.payment.manage.mappers.payment.RefundMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper;
import au.com.royalpay.payment.manage.mappers.payment.*;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
import au.com.royalpay.payment.manage.mappers.system.CustomerRelationAlipayMapper;
import au.com.royalpay.payment.manage.mappers.system.OrgMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.organizations.core.OrgManager;
import au.com.royalpay.payment.manage.tradelog.beans.PreRefundQueryBean;
@ -29,12 +26,10 @@ import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
@ -42,24 +37,13 @@ import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
import net.sf.jasperreports.export.ExporterInput;
import net.sf.jasperreports.export.OutputStreamExporterOutput;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
import net.sf.jasperreports.export.SimpleXlsxReportConfiguration;
import net.sf.jasperreports.export.*;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -67,6 +51,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@ -82,9 +68,6 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import static au.com.royalpay.payment.manage.permission.utils.OrgCheckUtils.checkOrgPermission;
@ -107,6 +90,10 @@ public class TradeLogServiceImpl implements TradeLogService {
@Resource
private PaymentApi paymentApi;
@Resource
private ClearingDetailMapper clearingDetailMapper;
@Resource
private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper;
@Resource
private MpPaymentApi mpPaymentApi;
@Resource
private TransactionMapper transactionMapper;
@ -170,7 +157,7 @@ public class TradeLogServiceImpl implements TradeLogService {
@Override
public JSONObject listAllTradeLogs(TradeLogQuery query, JSONObject manager) {
JSONObject params = query.toParams(null);
if (ManagerRole.BD_USER.hasRole(manager.getIntValue("role"))&& !ManagerRole.ORG_MANAGER.hasRole(manager.getIntValue("role"))) {
if (ManagerRole.BD_USER.hasRole(manager.getIntValue("role")) && !ManagerRole.ORG_MANAGER.hasRole(manager.getIntValue("role"))) {
params.put("bd_user", manager.getString("manager_id"));
}
if (query.isOnlyGroup() && ManagerRole.BD_LEADER.hasRole(manager.getIntValue("role"))) {
@ -180,7 +167,7 @@ public class TradeLogServiceImpl implements TradeLogService {
params.put("bd_group_bd", query.getGroup_bd());
}
}
orgManager.checkOrgIds(manager,params);
orgManager.checkOrgIds(manager, params);
PageList<JSONObject> logs = orderMapper.listOrders(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
JSONObject result = PageListUtils.buildPageListResult(logs);
JSONObject analysis = orderMapper.analysisOrders(params);
@ -189,7 +176,6 @@ public class TradeLogServiceImpl implements TradeLogService {
}
@Override
public List<JSONObject> listOrderRefunds(String orderId, String timezone) {
List<JSONObject> refunds = refundMapper.listOrderRefunds(orderId, new PageBounds(Order.formString("create_time.desc")));
@ -404,8 +390,8 @@ public class TradeLogServiceImpl implements TradeLogService {
obj.put("client_id", orderLog.getInteger("client_id"));
obj.put("customer_id", orderLog.getString("customer_id"));
obj.put("name_remak", name_remark);
obj.put("channel",order.getString("channel"));
obj.put("update_time",new Date());
obj.put("channel", order.getString("channel"));
obj.put("update_time", new Date());
JSONObject client_coustom = clientCustomersMapper.getClientCustomer(orderLog.getInteger("client_id"), orderLog.getString("customer_id"));
if (null == client_coustom) {
clientCustomersMapper.insert(obj);
@ -438,7 +424,7 @@ public class TradeLogServiceImpl implements TradeLogService {
new PageBounds(query.getPage(), query.getLimit(), Order.formString("transaction_time.desc")));
TimeZoneUtils.switchTimeZone(logs, timezone, "create_time", "confirm_time", "transaction_time");
JSONObject result = PageListUtils.buildPageListResult(logs);
JSONObject analysis = transactionMapper.analysisTransFlow(params);
JSONObject analysis = analysisTransLogs(logs);
if (analysis.containsKey("paid_fee") && analysis.containsKey("refund_fee")) {
analysis.put("actual_fee", analysis.getBigDecimal("paid_fee").add(analysis.getBigDecimal("refund_fee")));
}
@ -454,9 +440,12 @@ public class TradeLogServiceImpl implements TradeLogService {
params.put("client_id", client_id);
List<JSONObject> logs = transactionMapper.listTransFlow(params);
TimeZoneUtils.switchTimeZoneToString(logs, timezone, "dd/MM/yyyy HH:mm:ss", Arrays.asList("transaction_time"));
final JSONObject analysis = analysisTransLogs(logs);
JSONObject result = new JSONObject();
result.put("data", logs);
JSONObject analysis = transactionMapper.analysisTransFlow(params);
// JSONObject analysis = transactionMapper.analysisTransFlow(params);
analysis.put("balance", transactionMapper.analysisBalance(params));
if (analysis.containsKey("paid_fee") && analysis.containsKey("refund_fee")) {
analysis.put("actual_fee", analysis.getBigDecimal("paid_fee").add(analysis.getBigDecimal("refund_fee")));
@ -465,6 +454,92 @@ public class TradeLogServiceImpl implements TradeLogService {
return result;
}
private JSONObject analysisTransLogs(List<JSONObject> logs) {
final JSONObject analysis = new JSONObject();
analysis.put("order_count", logs.size());
analysis.put("display_amount", logs.parallelStream()
.filter(log -> log.getBigDecimal("display_amount") != null && !"CNY".equals(log.getString("currency")))
.map(log -> log.getBigDecimal("display_amount"))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("pre_display_amount", logs.parallelStream()
.filter(log -> log.getBigDecimal("display_amount") != null && !"CNY".equals(log.getString("currency")) && log.getBooleanValue("pre_authorization"))
.map(log -> log.getBigDecimal("display_amount"))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("cny_display_amount", logs.parallelStream()
.filter(log -> log.getBigDecimal("display_amount") != null && "CNY".equals(log.getString("currency")))
.map(log -> log.getBigDecimal("display_amount"))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("pre_cny_display_amount", logs.parallelStream()
.filter(log -> log.getBigDecimal("display_amount") != null && "CNY".equals(log.getString("currency")) && log.getBooleanValue("pre_authorization"))
.map(log -> log.getBigDecimal("display_amount"))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("paid_fee", logs.parallelStream()
.filter(log -> !log.getBooleanValue("system_generate") && "Credit".equals(log.getString("transaction_type")) && !"Settlement".equals(log.getString("channel")))
.map(log -> log.getBigDecimal("clearing_amount"))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("refund_fee", logs.parallelStream()
.filter(log -> log.getString("refund_id") != null && !"Settlement".equals(log.getString("channel")))
.map(log -> getSymbol(log).multiply(log.getBigDecimal("clearing_amount"))).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("pre_refund_fee", logs.parallelStream()
.filter(log -> log.getString("refund_id") != null && !"Settlement".equals(log.getString("channel")) && log.getBooleanValue("pre_authorization"))
.map(log -> getSymbol(log).multiply(log.getBigDecimal("clearing_amount"))).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
logs.parallelStream()
.filter(log -> "Settlement".equals(log.getString("channel")) &&
log.getString("system_transaction_id").contains("MERCHANT"))
.filter(log -> transactionMapper.listTransactionsOfClearingOrder(log.getIntValue("clearing_order"), new PageBounds(1, 1))
.stream().anyMatch(trans -> trans.getBigDecimal("settle_amount") == null))
.forEach(settleLog -> {
JSONObject detail = clearingDetailMapper.findByDetailId(settleLog.getIntValue("clearing_order"));
settleLog.put("settle_amount", detail.getBigDecimal("clearing_amount"));
settleLog.put("total_surcharge", detail.getBigDecimal("total_charge"));
settleLog.put("royal_surcharge", detail.getBigDecimal("royalpay_charge"));
settleLog.put("channel_surcharge", detail.getBigDecimal("wechat_charge"));
});
analysis.put("total_settle_amount", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.map(log -> getSymbol(log).multiply(log.getBigDecimal("settle_amount")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("total_royal_surcharge", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.map(log -> getSymbol(log).multiply(log.getBigDecimal("royal_surcharge")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("total_surcharge", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.map(log -> getSymbol(log).multiply(log.getBigDecimal("total_surcharge")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("wechat_fee", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.filter(log -> "WechatSettlement".contains(log.getString("channel")))
.map(log -> getSymbol(log).multiply(log.getBigDecimal("channel_surcharge")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("alipay_fee", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.filter(log -> "Alipay".equals(log.getString("channel")))
.map(log -> getSymbol(log).multiply(log.getBigDecimal("channel_surcharge")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("jd_fee", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.filter(log -> "jd".equals(log.getString("channel")))
.map(log -> getSymbol(log).multiply(log.getBigDecimal("channel_surcharge")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("bestpay_fee", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.filter(log -> "Bestpay".equals(log.getString("channel")))
.map(log -> getSymbol(log).multiply(log.getBigDecimal("channel_surcharge")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
analysis.put("alipay_online_fee", logs.parallelStream()
.filter(log -> log.getBigDecimal("settle_amount") != null)
.filter(log -> "AlipayOnline".equals(log.getString("channel")))
.map(log -> getSymbol(log).multiply(log.getBigDecimal("channel_surcharge")))
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
return analysis;
}
private BigDecimal getSymbol(JSONObject log) {
return "Credit".equals(log.getString("transaction_type")) || "Settlement".equals(log.getString("channel")) ? BigDecimal.ONE : BigDecimal.valueOf(-1);
}
@Override
public void exportTransFlow(TradeLogQuery query, JSONObject partner, HttpServletResponse response) throws Exception {
// File jasperFile = trans_flow.getFile();

@ -37,18 +37,20 @@
</select>
<select id="listTransFlow" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.*,ifnull(o.client_order_id,'--') client_order_id,if(t.refund_id is NOT
NULL,'refund',if(t.transaction_type='Debit' AND t.system_generate=0,'clearing','payment')) trans_type,
t.system_transaction_id,
if(t.transaction_type='Debit' AND t.refund_id is NULL and
t.system_generate=0,if(locate('MERCHANT',t.system_transaction_id)>0,'Transfer to Merchant','Merchant Service
Fee'),t.order_id) order_id2,
if(t.transaction_type='Debit' AND t.refund_id is NULL and t.system_generate=0,'-',CASE t.clearing_status
SELECT t.*,
ifnull(o.client_order_id,'--') client_order_id,
if(t.channel='Settlement','clearing',
if(t.transaction_type='Credit','payment','refund')) trans_type,
t.system_transaction_id,
if(t.channel='Settlement',
if(locate('MERCHANT',t.system_transaction_id)>0, 'Transfer to Merchant','Merchant Service Fee'),
if(t.system_generate=0,t.order_id,t.remark)) order_id2,
if(t.channel='Settlement','-',CASE t.clearing_status
WHEN 0 THEN 'ReadyToClear'
WHEN 1 THEN 'Cleared'
WHEN 2 THEN 'Preauthorised'
END) clear_status,
o.order_detail,o.display_amount,o.channel,o.currency
o.order_detail,o.display_amount,o.channel,o.currency,o.pre_authorization
FROM pmt_transactions t
LEFT JOIN pmt_orders o ON o.order_id=t.order_id
<where>

Loading…
Cancel
Save