|
|
|
@ -18,32 +18,28 @@ public class AgentCommissionAnalysis {
|
|
|
|
|
private int orgId;
|
|
|
|
|
private int year;
|
|
|
|
|
private int month;
|
|
|
|
|
private BigDecimal alipayChargeRate;
|
|
|
|
|
private BigDecimal wechatChargeRate;
|
|
|
|
|
private BigDecimal jdChargeRate;
|
|
|
|
|
private BigDecimal alipayonlineChargeRate;
|
|
|
|
|
private BigDecimal rate;
|
|
|
|
|
private String channel;
|
|
|
|
|
private Map<Integer, List<JSONObject>> clientAnalysis = new HashMap<>();
|
|
|
|
|
private BigDecimal totalGrossAmount = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalChargeSum = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalRoyalPayCharge = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalOrgChargeSum = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalnetCharge = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalAgentCharge = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalAgentNetCharge = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalOrgCharge = BigDecimal.ZERO;
|
|
|
|
|
private BigDecimal totalOrgNetCharge = BigDecimal.ZERO;
|
|
|
|
|
private JSONObject org;
|
|
|
|
|
private JSONObject parentOrg;
|
|
|
|
|
|
|
|
|
|
public AgentCommissionAnalysis(int orgId, int year, int month, BigDecimal rate, String channel, BigDecimal alipayChargeRate, BigDecimal wechatChargeRate, BigDecimal jdChargeRate, BigDecimal alipayonlineChargeRate) {
|
|
|
|
|
public AgentCommissionAnalysis(int orgId, int year, int month, BigDecimal rate,String channel,JSONObject org,JSONObject parentOrg) {
|
|
|
|
|
this.orgId = orgId;
|
|
|
|
|
this.year = year;
|
|
|
|
|
this.month = month;
|
|
|
|
|
this.rate = rate;
|
|
|
|
|
this.channel = channel;
|
|
|
|
|
this.alipayChargeRate = alipayChargeRate;
|
|
|
|
|
this.wechatChargeRate = wechatChargeRate;
|
|
|
|
|
this.jdChargeRate = jdChargeRate;
|
|
|
|
|
this.alipayonlineChargeRate = alipayonlineChargeRate;
|
|
|
|
|
this.org = org;
|
|
|
|
|
this.parentOrg = parentOrg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AgentCommissionAnalysis attachAnalysis(JSONObject dayAnalysis, String channel) {
|
|
|
|
|
public AgentCommissionAnalysis attachAnalysis(JSONObject dayAnalysis,String channel) {
|
|
|
|
|
int clientId = dayAnalysis.getIntValue("client_id");
|
|
|
|
|
List<JSONObject> clientTrades = clientAnalysis.get(clientId);
|
|
|
|
|
if (clientTrades == null) {
|
|
|
|
@ -51,54 +47,50 @@ public class AgentCommissionAnalysis {
|
|
|
|
|
clientAnalysis.put(clientId, clientTrades);
|
|
|
|
|
}
|
|
|
|
|
Date tradeDate = dayAnalysis.getDate("trade_date");
|
|
|
|
|
BigDecimal total = dayAnalysis.getBigDecimal("total");
|
|
|
|
|
BigDecimal grossAmount = dayAnalysis.getBigDecimal("total");
|
|
|
|
|
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel+"_rate_value");
|
|
|
|
|
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
|
|
|
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
|
|
|
BigDecimal thirdPartyPaymentCharge = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal agentCharge = grossAmount.multiply(dayRate.divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
BigDecimal orgCharge = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal orgNetCharge = BigDecimal.ZERO;
|
|
|
|
|
switch (channel){
|
|
|
|
|
case "alipay":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(alipayChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
orgCharge = grossAmount.multiply(org.getBigDecimal("alipay_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("alipay_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
|
|
|
|
|
break;
|
|
|
|
|
case "wechat":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(wechatChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
orgCharge = grossAmount.multiply(org.getBigDecimal("wechat_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("wechat_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
|
|
|
|
|
break;
|
|
|
|
|
case "jd":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(jdChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
orgCharge = grossAmount.multiply(org.getBigDecimal("jd_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("jd_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
|
|
|
|
|
break;
|
|
|
|
|
case "alipayonline":
|
|
|
|
|
thirdPartyPaymentCharge = total.multiply(alipayonlineChargeRate).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
orgCharge = grossAmount.multiply(org.getBigDecimal("alipayonline_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
orgNetCharge = orgCharge.subtract(grossAmount.multiply(parentOrg.getBigDecimal("alipayonline_rate_value").divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP)));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal netCharge = royalpayCharge.subtract(thirdPartyPaymentCharge);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal orgCharge = dayCharge.subtract(royalpayCharge);
|
|
|
|
|
|
|
|
|
|
totalGrossAmount = totalGrossAmount.add(total);
|
|
|
|
|
totalChargeSum = totalChargeSum.add(dayCharge);
|
|
|
|
|
totalRoyalPayCharge = totalRoyalPayCharge.add(royalpayCharge);
|
|
|
|
|
totalOrgChargeSum = totalOrgChargeSum.add(orgCharge);
|
|
|
|
|
totalnetCharge = totalnetCharge.add(netCharge);
|
|
|
|
|
totalGrossAmount = totalGrossAmount.add(grossAmount);
|
|
|
|
|
totalAgentCharge = totalAgentCharge.add(agentCharge);
|
|
|
|
|
totalAgentNetCharge = totalAgentNetCharge.add(orgNetCharge);
|
|
|
|
|
totalOrgCharge = totalOrgCharge.add(orgCharge);
|
|
|
|
|
totalOrgNetCharge = totalOrgNetCharge.add(orgNetCharge);
|
|
|
|
|
if (!clientTrades.isEmpty()) {
|
|
|
|
|
JSONObject item = clientTrades.get(clientTrades.size() - 1);
|
|
|
|
|
BigDecimal rate = item.getBigDecimal("client_rate");
|
|
|
|
|
if (rate.compareTo(dayRate) == 0) {
|
|
|
|
|
BigDecimal gross = item.getBigDecimal("gross_amount").add(total);
|
|
|
|
|
BigDecimal gross = item.getBigDecimal("gross_amount").add(grossAmount);
|
|
|
|
|
item.put("gross_amount", gross);
|
|
|
|
|
BigDecimal totalCharge = item.getBigDecimal("total_charge").add(dayCharge);
|
|
|
|
|
BigDecimal totalCharge = item.getBigDecimal("total_charge").add(agentCharge);
|
|
|
|
|
item.put("total_charge", totalCharge);
|
|
|
|
|
BigDecimal totalRoyalCharge = item.getBigDecimal("royalpay_charge").add(royalpayCharge);
|
|
|
|
|
item.put("royalpay_charge", totalRoyalCharge);
|
|
|
|
|
BigDecimal totalOrgCharge = item.getBigDecimal("org_charge").add(orgCharge);
|
|
|
|
|
item.put("org_charge", totalOrgCharge);
|
|
|
|
|
BigDecimal totalRoyalpayClearingCharge = item.getBigDecimal("net_charge").add(netCharge);
|
|
|
|
|
item.put("net_charge", totalRoyalpayClearingCharge);
|
|
|
|
|
BigDecimal totalRoyalpayClearingCharge = item.getBigDecimal("org_net_charge").add(orgNetCharge);
|
|
|
|
|
item.put("org_net_charge", totalRoyalpayClearingCharge);
|
|
|
|
|
Date from = item.getDate("date_from");
|
|
|
|
|
Date to = item.getDate("date_to");
|
|
|
|
|
from = from.before(tradeDate) ? from : tradeDate;
|
|
|
|
@ -114,12 +106,11 @@ public class AgentCommissionAnalysis {
|
|
|
|
|
item.put("date_from", tradeDate);
|
|
|
|
|
item.put("date_to", tradeDate);
|
|
|
|
|
item.put("client_rate", dayRate);
|
|
|
|
|
item.put("gross_amount", total);
|
|
|
|
|
item.put("total_charge", dayCharge);
|
|
|
|
|
item.put("royalpay_charge", royalpayCharge);
|
|
|
|
|
item.put("gross_amount", grossAmount);
|
|
|
|
|
item.put("total_charge", agentCharge);
|
|
|
|
|
item.put("org_charge", orgCharge);
|
|
|
|
|
item.put("channel",channel);
|
|
|
|
|
item.put("net_charge",netCharge);
|
|
|
|
|
item.put("org_net_charge",orgNetCharge);
|
|
|
|
|
clientTrades.add(item);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
@ -132,10 +123,9 @@ public class AgentCommissionAnalysis {
|
|
|
|
|
result.put("create_time", new Date());
|
|
|
|
|
result.put("org_rate", rate);
|
|
|
|
|
result.put("gross_amount", totalGrossAmount);
|
|
|
|
|
result.put("total_charge", totalChargeSum);
|
|
|
|
|
result.put("royalpay_charge", totalRoyalPayCharge);
|
|
|
|
|
result.put("org_charge", totalOrgChargeSum);
|
|
|
|
|
result.put("net_charge",totalnetCharge);
|
|
|
|
|
result.put("total_charge", totalAgentCharge);
|
|
|
|
|
result.put("org_charge", totalOrgCharge);
|
|
|
|
|
result.put("org_net_charge",totalOrgNetCharge);
|
|
|
|
|
result.put("channel",channel);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -152,4 +142,4 @@ public class AgentCommissionAnalysis {
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|