|
|
|
@ -10,9 +10,11 @@ import au.com.royalpay.payment.manage.mappers.financial.FinancialPartnerCommissi
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.financial.FinancialPartnerCommissionMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.financial.FinancialReferrerCommissionDetailMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.financial.FinancialReferrerCommissionMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.financial.FinancialSeniorPartnerCommissionDetailMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.financial.FinancialSeniorPartnerCommissionMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.OrgMapper;
|
|
|
|
|
import au.com.royalpay.payment.tools.CommonConsts;
|
|
|
|
|
import au.com.royalpay.payment.tools.env.SysConfigManager;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
@ -30,6 +32,7 @@ import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
@ -64,6 +67,8 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
private SysConfigManager sysConfigManager;
|
|
|
|
|
@Resource
|
|
|
|
|
private FinancialSeniorPartnerCommissionMapper financialSeniorPartnerCommissionMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private FinancialSeniorPartnerCommissionDetailMapper financialSeniorPartnerCommissionDetailMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> listAvailableMonths(String year) {
|
|
|
|
@ -78,7 +83,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
item.put("royalpay_charge", chargeInfo.getString("royalpay_charge"));
|
|
|
|
|
item.put("org_charge", chargeInfo.getString("org_charge"));
|
|
|
|
|
JSONObject referrerChargeInfo = getReferrerPrizeInfo(item.getString("monthstr"));
|
|
|
|
|
item.put("referrer_charge",referrerChargeInfo.getString("org_charge"));
|
|
|
|
|
item.put("referrer_charge", referrerChargeInfo.getString("org_charge"));
|
|
|
|
|
item.put("total_charge", chargeInfo.getBigDecimal("org_charge").add(referrerChargeInfo.getBigDecimal("org_charge")));
|
|
|
|
|
monthObjs.add(item);
|
|
|
|
|
}
|
|
|
|
@ -226,7 +231,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
sumResult.put("net_charge", netCharge);
|
|
|
|
|
sumResult.put("client_moniker", clientMoniker);
|
|
|
|
|
sumResult.put("channel_detail", entry.getValue());
|
|
|
|
|
sumResult.put("type",type);
|
|
|
|
|
sumResult.put("type", type);
|
|
|
|
|
partnerClientInfos.add(sumResult);
|
|
|
|
|
}
|
|
|
|
|
result.put("partner_client_infos", partnerClientInfos);
|
|
|
|
@ -239,7 +244,14 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
result.put("total_charge", resultTotalCharge);
|
|
|
|
|
result.put("royalPay_charge", resultRoyalpayCharge);
|
|
|
|
|
result.put("net_charge", resultNetCharge);
|
|
|
|
|
result.put("city_partner_charge", resultOrgCharge);
|
|
|
|
|
result.put("own_charge", resultOrgCharge);
|
|
|
|
|
JSONObject senior = financialSeniorPartnerCommissionMapper.find(year, month, orgId);
|
|
|
|
|
if (senior != null) {
|
|
|
|
|
result.put("senior_partner_charge", senior.getBigDecimal("gross_amount"));
|
|
|
|
|
result.put("city_partner_charge", resultOrgCharge.add(senior.getBigDecimal("gross_amount")));
|
|
|
|
|
} else {
|
|
|
|
|
result.put("city_partner_charge", resultOrgCharge);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -252,7 +264,6 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject sysConfig = sysConfigManager.getSysConfig();
|
|
|
|
|
BigDecimal alipayChargeRate = new BigDecimal("0.6");
|
|
|
|
|
BigDecimal wechatChargeRate = new BigDecimal("0.6");
|
|
|
|
@ -282,16 +293,15 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
for (JSONObject analysisDay : transactionAnalysis) {
|
|
|
|
|
int orgId = analysisDay.getIntValue("org_id");
|
|
|
|
|
JSONObject org = orgMapper.findOne(orgId);
|
|
|
|
|
if(org.getIntValue("parent_org_id")>0){
|
|
|
|
|
if (org.getIntValue("parent_org_id") > 0) {
|
|
|
|
|
orgIds.add(orgId);
|
|
|
|
|
}
|
|
|
|
|
if (org == null) {
|
|
|
|
|
// shall never happen
|
|
|
|
|
throw new ServerErrorException("Organization Id not exists:" + orgId);
|
|
|
|
|
}
|
|
|
|
|
financialPartnerCommissionDetailMapper.clearData(year, month,org.getIntValue("commission_type"));
|
|
|
|
|
financialPartnerCommissionMapper.clearData(year, month,org.getIntValue("commission_type"));
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
@ -302,10 +312,10 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
CityPartnerCommissionAnalysis orgAnalysis = results.get(orgId + channel);
|
|
|
|
|
if (orgAnalysis == null) {
|
|
|
|
|
orgAnalysis = new CityPartnerCommissionAnalysis(orgId, year, month, org.getBigDecimal(channel + "_rate_value"), key, alipayChargeRate,
|
|
|
|
|
wechatChargeRate, jdChargeRate, alipayonlineChargeRate,org.getBigDecimal("rate_value"),org.getIntValue("commission_type"));
|
|
|
|
|
wechatChargeRate, jdChargeRate, alipayonlineChargeRate, org.getBigDecimal("rate_value"), org.getIntValue("commission_type"));
|
|
|
|
|
results.put(orgId + channel, orgAnalysis);
|
|
|
|
|
}
|
|
|
|
|
orgAnalysis.calculator(analysisDay, channel,org.getIntValue("commission_type"));
|
|
|
|
|
orgAnalysis.calculator(analysisDay, channel, org.getIntValue("commission_type"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
for (CityPartnerCommissionAnalysis commission : results.values()) {
|
|
|
|
@ -317,11 +327,12 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
financialPartnerCommissionDetailMapper.save(detail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Runnable task = ()->{
|
|
|
|
|
orgIds.forEach((p)->{
|
|
|
|
|
generateAgent(monthStr,p);
|
|
|
|
|
Runnable task = () -> {
|
|
|
|
|
orgIds.forEach((p) -> {
|
|
|
|
|
generateAgent(monthStr, p);
|
|
|
|
|
});
|
|
|
|
|
generateReferrer(monthStr);
|
|
|
|
|
generateSenior(monthStr);
|
|
|
|
|
};
|
|
|
|
|
new Thread(task).start();
|
|
|
|
|
}
|
|
|
|
@ -559,7 +570,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
JSONObject sum = new JSONObject();
|
|
|
|
|
sum.put("gross_amount", 0);
|
|
|
|
|
sum.put("org_charge", 0);
|
|
|
|
|
sum.put("total_charge",0);
|
|
|
|
|
sum.put("total_charge", 0);
|
|
|
|
|
List<JSONObject> referrerPrizes = financialAgentCommissionMapper.list(year, month);
|
|
|
|
|
for (JSONObject prize : referrerPrizes) {
|
|
|
|
|
plusKey(sum, prize, "gross_amount");
|
|
|
|
@ -587,11 +598,11 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
BigDecimal royalpay_charge = BigDecimal.ZERO;
|
|
|
|
|
List<JSONObject> partnerPrizeList = financialPartnerCommissionDetailMapper.listDetailByMonth(year,month);
|
|
|
|
|
List<JSONObject> partnerPrizeList = financialPartnerCommissionDetailMapper.listDetailByMonth(year, month);
|
|
|
|
|
Map<String, JSONObject> countPartnerPrizeMap = new HashMap<>();
|
|
|
|
|
for (JSONObject p : partnerPrizeList) {
|
|
|
|
|
royalpay_charge = royalpay_charge.add(p.getBigDecimal("royalpay_charge"));
|
|
|
|
|
String key = p.getString("client_id")+p.getString("channel").toLowerCase();
|
|
|
|
|
String key = p.getString("client_id") + p.getString("channel").toLowerCase();
|
|
|
|
|
JSONObject partnerTmp = countPartnerPrizeMap.get(key);
|
|
|
|
|
if (partnerTmp == null) {
|
|
|
|
|
JSONObject partner = new JSONObject();
|
|
|
|
@ -626,11 +637,11 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
detail.put("date_from", format.format(detail.get("date_from")));
|
|
|
|
|
detail.put("date_to", format.format(detail.get("date_to")));
|
|
|
|
|
String key = detail.getString("client_id");
|
|
|
|
|
detail.put("royalpay_charge",BigDecimal.ZERO);
|
|
|
|
|
if(countPartnerPrizeMap.get(key+detail.getString("channel").toLowerCase())!=null){
|
|
|
|
|
detail.put("royalpay_charge",countPartnerPrizeMap.get(key+detail.getString("channel")).getBigDecimal("royalpay_charge"));
|
|
|
|
|
}else {
|
|
|
|
|
detail.put("royalpay_charge",BigDecimal.ZERO);
|
|
|
|
|
detail.put("royalpay_charge", BigDecimal.ZERO);
|
|
|
|
|
if (countPartnerPrizeMap.get(key + detail.getString("channel").toLowerCase()) != null) {
|
|
|
|
|
detail.put("royalpay_charge", countPartnerPrizeMap.get(key + detail.getString("channel")).getBigDecimal("royalpay_charge"));
|
|
|
|
|
} else {
|
|
|
|
|
detail.put("royalpay_charge", BigDecimal.ZERO);
|
|
|
|
|
}
|
|
|
|
|
if (detailMap.containsKey(key)) {
|
|
|
|
|
detailMap.get(key).add(detail);
|
|
|
|
@ -704,9 +715,10 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void generateSenior(String monthStr) {
|
|
|
|
|
List<String> seniorOrgs = orgMapper.listSeniorOrgId(0);
|
|
|
|
|
if(CollectionUtils.isEmpty(seniorOrgs)){
|
|
|
|
|
if (CollectionUtils.isEmpty(seniorOrgs)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Date mon = checkMonth(monthStr);
|
|
|
|
@ -715,24 +727,32 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
JSONObject sysConfig = sysConfigManager.getSysConfig();
|
|
|
|
|
BigDecimal rate = sysConfig.getBigDecimal("senior_charge_rate");
|
|
|
|
|
if(rate==null){
|
|
|
|
|
rate = new BigDecimal("0.0006");
|
|
|
|
|
BigDecimal rate = sysConfig.getBigDecimal("senior_charge_rate").divide(CommonConsts.HUNDRED);
|
|
|
|
|
if (rate == null) {
|
|
|
|
|
rate = new BigDecimal("0.0006");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
List<JSONObject> seniorOrgAnalysis = financialPartnerCommissionMapper.analysisSenior(year,month,seniorOrgs);
|
|
|
|
|
financialSeniorPartnerCommissionMapper.clearData(year, month);
|
|
|
|
|
|
|
|
|
|
BigDecimal finalRate = rate;
|
|
|
|
|
seniorOrgAnalysis.parallelStream().forEach(p->{
|
|
|
|
|
seniorOrgs.parallelStream().forEach(p -> {
|
|
|
|
|
List<String> seniorSubOrgs = orgMapper.listSeniorOrgId(Integer.parseInt(p));
|
|
|
|
|
if (CollectionUtils.isEmpty(seniorSubOrgs)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject seniorOrgAnalysis = financialPartnerCommissionMapper.analysisSeniorForGenerate(year, month, seniorSubOrgs);
|
|
|
|
|
JSONObject record = new JSONObject();
|
|
|
|
|
record.put("org_id",p.getString("org_id"));
|
|
|
|
|
record.put("year",year);
|
|
|
|
|
record.put("month",month);
|
|
|
|
|
record.put("create_time",now);
|
|
|
|
|
record.put("org_rate", finalRate);
|
|
|
|
|
record.put("gross_amount",p.getBigDecimal("gross_amount"));
|
|
|
|
|
record.put("org_id", p);
|
|
|
|
|
record.put("year", year);
|
|
|
|
|
record.put("month", month);
|
|
|
|
|
record.put("create_time", now);
|
|
|
|
|
record.put("org_rate", finalRate.multiply(CommonConsts.HUNDRED));
|
|
|
|
|
record.put("gross_amount", seniorOrgAnalysis.getBigDecimal("gross_amount"));
|
|
|
|
|
record.put("net_charge", seniorOrgAnalysis.getBigDecimal("gross_amount").multiply(finalRate));
|
|
|
|
|
financialSeniorPartnerCommissionMapper.save(record);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -743,9 +763,19 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
List<String> orgs = orgMapper.listSeniorOrgId(param.getIntValue("org_id"));
|
|
|
|
|
List<JSONObject> result = financialPartnerCommissionMapper.analysisSenior(year,month,orgs);
|
|
|
|
|
result.parallelStream().forEach(p->{
|
|
|
|
|
p.put("gross_amount",p.getBigDecimal("gross_amount").multiply(new BigDecimal("0.0005")).setScale(2, BigDecimal.ROUND_HALF_DOWN));
|
|
|
|
|
if (CollectionUtils.isEmpty(orgs)) {
|
|
|
|
|
return Collections.EMPTY_LIST;
|
|
|
|
|
}
|
|
|
|
|
List<JSONObject> result = financialPartnerCommissionMapper.analysisSenior(year, month, orgs);
|
|
|
|
|
JSONObject sysConfig = sysConfigManager.getSysConfig();
|
|
|
|
|
BigDecimal rate = sysConfig.getBigDecimal("senior_charge_rate").divide(CommonConsts.HUNDRED);
|
|
|
|
|
if (rate == null) {
|
|
|
|
|
rate = new BigDecimal("0.0006");
|
|
|
|
|
}
|
|
|
|
|
BigDecimal finalRate = rate;
|
|
|
|
|
result.parallelStream().forEach(p -> {
|
|
|
|
|
p.put("net_charge", p.getBigDecimal("gross_amount").multiply(finalRate).setScale(2, BigDecimal.ROUND_HALF_DOWN));
|
|
|
|
|
p.put("org_rate", finalRate.multiply(CommonConsts.HUNDRED));
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -757,7 +787,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
|
|
|
|
|
monthCal.setTime(monthDate);
|
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
return financialSeniorPartnerCommissionMapper.find(year,month,orgId);
|
|
|
|
|
return financialSeniorPartnerCommissionMapper.find(year, month, orgId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|