|
|
@ -1,5 +1,27 @@
|
|
|
|
package au.com.royalpay.payment.manage.citypartner.core.impls;
|
|
|
|
package au.com.royalpay.payment.manage.citypartner.core.impls;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.AgentCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.AgentCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.CityPartnerCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.CityPartnerCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.ReferrerCommissionAnalysis;
|
|
|
|
import au.com.royalpay.payment.manage.citypartner.beans.ReferrerCommissionAnalysis;
|
|
|
@ -16,26 +38,6 @@ import au.com.royalpay.payment.tools.env.SysConfigManager;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Created by yixian on 2017-03-08.
|
|
|
|
* Created by yixian on 2017-03-08.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -195,6 +197,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
BigDecimal netCharge = BigDecimal.ZERO;
|
|
|
|
BigDecimal netCharge = BigDecimal.ZERO;
|
|
|
|
BigDecimal orgCharge = BigDecimal.ZERO;
|
|
|
|
BigDecimal orgCharge = BigDecimal.ZERO;
|
|
|
|
String clientMoniker = "";
|
|
|
|
String clientMoniker = "";
|
|
|
|
|
|
|
|
int type = 1;
|
|
|
|
for (JSONObject jsonObject : entry.getValue()) {
|
|
|
|
for (JSONObject jsonObject : entry.getValue()) {
|
|
|
|
grossAmount = grossAmount.add(jsonObject.getBigDecimal("gross_amount"));
|
|
|
|
grossAmount = grossAmount.add(jsonObject.getBigDecimal("gross_amount"));
|
|
|
|
totalCharge = totalCharge.add(jsonObject.getBigDecimal("total_charge"));
|
|
|
|
totalCharge = totalCharge.add(jsonObject.getBigDecimal("total_charge"));
|
|
|
@ -204,6 +207,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
netCharge = netCharge.add(jsonObject.getBigDecimal("net_charge"));
|
|
|
|
netCharge = netCharge.add(jsonObject.getBigDecimal("net_charge"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clientMoniker = jsonObject.getString("client_moniker");
|
|
|
|
clientMoniker = jsonObject.getString("client_moniker");
|
|
|
|
|
|
|
|
type = jsonObject.getIntValue("type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resultGrossAmount = resultGrossAmount.add(grossAmount);
|
|
|
|
resultGrossAmount = resultGrossAmount.add(grossAmount);
|
|
|
|
resultTotalCharge = resultTotalCharge.add(totalCharge);
|
|
|
|
resultTotalCharge = resultTotalCharge.add(totalCharge);
|
|
|
@ -217,6 +221,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
sumResult.put("net_charge", netCharge);
|
|
|
|
sumResult.put("net_charge", netCharge);
|
|
|
|
sumResult.put("client_moniker", clientMoniker);
|
|
|
|
sumResult.put("client_moniker", clientMoniker);
|
|
|
|
sumResult.put("channel_detail", entry.getValue());
|
|
|
|
sumResult.put("channel_detail", entry.getValue());
|
|
|
|
|
|
|
|
sumResult.put("type",type);
|
|
|
|
partnerClientInfos.add(sumResult);
|
|
|
|
partnerClientInfos.add(sumResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.put("partner_client_infos", partnerClientInfos);
|
|
|
|
result.put("partner_client_infos", partnerClientInfos);
|
|
|
@ -242,8 +247,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
financialPartnerCommissionDetailMapper.clearData(year, month);
|
|
|
|
|
|
|
|
financialPartnerCommissionMapper.clearData(year, month);
|
|
|
|
|
|
|
|
JSONObject sysConfig = sysConfigManager.getSysConfig();
|
|
|
|
JSONObject sysConfig = sysConfigManager.getSysConfig();
|
|
|
|
BigDecimal alipayChargeRate = new BigDecimal("0.6");
|
|
|
|
BigDecimal alipayChargeRate = new BigDecimal("0.6");
|
|
|
|
BigDecimal wechatChargeRate = new BigDecimal("0.6");
|
|
|
|
BigDecimal wechatChargeRate = new BigDecimal("0.6");
|
|
|
@ -267,29 +271,36 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
channelMap.put("Bestpay", "Bestpay");
|
|
|
|
channelMap.put("Bestpay", "Bestpay");
|
|
|
|
channelMap.put("jd", "jd");
|
|
|
|
channelMap.put("jd", "jd");
|
|
|
|
channelMap.put("AlipayOnline", "AlipayOnline");
|
|
|
|
channelMap.put("AlipayOnline", "AlipayOnline");
|
|
|
|
|
|
|
|
Set<Integer> orgIds = new HashSet<>();
|
|
|
|
List<JSONObject> transactionAnalysis = transactionMapper.listTransactionsForCityPartnerCommission(year, month);
|
|
|
|
List<JSONObject> transactionAnalysis = transactionMapper.listTransactionsForCityPartnerCommission(year, month);
|
|
|
|
Map<String, CityPartnerCommissionAnalysis> results = new HashMap<>();
|
|
|
|
Map<String, CityPartnerCommissionAnalysis> results = new HashMap<>();
|
|
|
|
for (JSONObject analysisDay : transactionAnalysis) {
|
|
|
|
for (JSONObject analysisDay : transactionAnalysis) {
|
|
|
|
String key = analysisDay.getString("channel");
|
|
|
|
|
|
|
|
String channel = analysisDay.getString("channel");
|
|
|
|
|
|
|
|
if (!channelMap.containsKey(key)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int orgId = analysisDay.getIntValue("org_id");
|
|
|
|
int orgId = analysisDay.getIntValue("org_id");
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject org = orgMapper.findOne(orgId);
|
|
|
|
JSONObject org = orgMapper.findOne(orgId);
|
|
|
|
|
|
|
|
if(org.getIntValue("parent_org_id")>0){
|
|
|
|
|
|
|
|
orgIds.add(orgId);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (org == null) {
|
|
|
|
if (org == null) {
|
|
|
|
// shall never happen
|
|
|
|
// shall never happen
|
|
|
|
throw new ServerErrorException("Organization Id not exists:" + orgId);
|
|
|
|
throw new ServerErrorException("Organization Id not exists:" + orgId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
financialPartnerCommissionDetailMapper.clearData(year, month,org.getIntValue("commission_type"));
|
|
|
|
|
|
|
|
financialPartnerCommissionMapper.clearData(year, month,org.getIntValue("commission_type"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String key = analysisDay.getString("channel");
|
|
|
|
|
|
|
|
String channel = analysisDay.getString("channel");
|
|
|
|
|
|
|
|
if (!channelMap.containsKey(key)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
channel = channel.toLowerCase();
|
|
|
|
channel = channel.toLowerCase();
|
|
|
|
CityPartnerCommissionAnalysis orgAnalysis = results.get(orgId + channel);
|
|
|
|
CityPartnerCommissionAnalysis orgAnalysis = results.get(orgId + channel);
|
|
|
|
if (orgAnalysis == null) {
|
|
|
|
if (orgAnalysis == null) {
|
|
|
|
orgAnalysis = new CityPartnerCommissionAnalysis(orgId, year, month, org.getBigDecimal(channel + "_rate_value"), key, alipayChargeRate,
|
|
|
|
orgAnalysis = new CityPartnerCommissionAnalysis(orgId, year, month, org.getBigDecimal(channel + "_rate_value"), key, alipayChargeRate,
|
|
|
|
wechatChargeRate, jdChargeRate, alipayonlineChargeRate);
|
|
|
|
wechatChargeRate, jdChargeRate, alipayonlineChargeRate,org.getBigDecimal("rate_value"),org.getIntValue("commission_type"));
|
|
|
|
results.put(orgId + channel, orgAnalysis);
|
|
|
|
results.put(orgId + channel, orgAnalysis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
orgAnalysis.attachAnalysis(analysisDay, channel);
|
|
|
|
orgAnalysis.calculator(analysisDay, channel,org.getIntValue("commission_type"));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (CityPartnerCommissionAnalysis commission : results.values()) {
|
|
|
|
for (CityPartnerCommissionAnalysis commission : results.values()) {
|
|
|
@ -301,7 +312,12 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
financialPartnerCommissionDetailMapper.save(detail);
|
|
|
|
financialPartnerCommissionDetailMapper.save(detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Runnable task = ()->{
|
|
|
|
|
|
|
|
orgIds.forEach((p)->{
|
|
|
|
|
|
|
|
generateAgent(monthStr,p);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
new Thread(task).start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -521,6 +537,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
JSONObject chargeInfo = getAgentPrizeInfo(item.getString("monthstr"));
|
|
|
|
JSONObject chargeInfo = getAgentPrizeInfo(item.getString("monthstr"));
|
|
|
|
item.put("org_charge", chargeInfo.getString("org_charge"));
|
|
|
|
item.put("org_charge", chargeInfo.getString("org_charge"));
|
|
|
|
item.put("gross_amount", chargeInfo.getString("gross_amount"));
|
|
|
|
item.put("gross_amount", chargeInfo.getString("gross_amount"));
|
|
|
|
|
|
|
|
item.put("total_charge", chargeInfo.getString("total_charge"));
|
|
|
|
monthObjs.add(item);
|
|
|
|
monthObjs.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return monthObjs;
|
|
|
|
return monthObjs;
|
|
|
@ -536,10 +553,12 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
JSONObject sum = new JSONObject();
|
|
|
|
JSONObject sum = new JSONObject();
|
|
|
|
sum.put("gross_amount", 0);
|
|
|
|
sum.put("gross_amount", 0);
|
|
|
|
sum.put("org_charge", 0);
|
|
|
|
sum.put("org_charge", 0);
|
|
|
|
|
|
|
|
sum.put("total_charge",0);
|
|
|
|
List<JSONObject> referrerPrizes = financialAgentCommissionMapper.list(year, month);
|
|
|
|
List<JSONObject> referrerPrizes = financialAgentCommissionMapper.list(year, month);
|
|
|
|
for (JSONObject prize : referrerPrizes) {
|
|
|
|
for (JSONObject prize : referrerPrizes) {
|
|
|
|
plusKey(sum, prize, "gross_amount");
|
|
|
|
plusKey(sum, prize, "gross_amount");
|
|
|
|
plusKey(sum, prize, "org_charge");
|
|
|
|
plusKey(sum, prize, "org_charge");
|
|
|
|
|
|
|
|
plusKey(sum, prize, "total_charge");
|
|
|
|
prize.put("monthstr", monthStr);
|
|
|
|
prize.put("monthstr", monthStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sum.put("referrer", referrerPrizes);
|
|
|
|
sum.put("referrer", referrerPrizes);
|
|
|
|