Merge branch 'develop_partnerTA' into develop

# Conflicts:
#	src/main/java/au/com/royalpay/payment/manage/organizations/beans/OrgInfo.java
#	src/main/ui/static/config/organizations/organizations.js
#	src/test/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImplTest.java
master
kira 6 years ago
commit 9ea1dabc33

@ -0,0 +1,241 @@
package au.com.royalpay.payment.manage.citypartner.beans;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import com.alibaba.fastjson.JSONObject;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by yixian on 2017-03-08.
*/
public class CityPartnerSeniorCommissionAnalysis {
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 BigDecimal orgRate;
private String channel;
private int commissionType;
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;
public CityPartnerSeniorCommissionAnalysis(int orgId, int year, int month, BigDecimal rate, String channel, BigDecimal alipayChargeRate,
BigDecimal wechatChargeRate, BigDecimal jdChargeRate, BigDecimal alipayonlineChargeRate, BigDecimal orgRate, int commissionType) {
this.orgId = orgId;
this.year = year;
this.month = month;
this.rate = rate;
this.channel = channel;
this.commissionType = commissionType;
this.alipayChargeRate = alipayChargeRate;
this.wechatChargeRate = wechatChargeRate;
this.jdChargeRate = jdChargeRate;
this.alipayonlineChargeRate = alipayonlineChargeRate;
this.orgRate = orgRate;
}
public CityPartnerSeniorCommissionAnalysis calculator(JSONObject dayAnalysis, String channel, int type) {
switch (type) {
case 1:
return attachAnalysis(dayAnalysis, channel);
case 3:
return attachNetCommissionAnalysis(dayAnalysis, channel);
default:
throw new ServerErrorException("unkonw calculate type");
}
}
public CityPartnerSeniorCommissionAnalysis attachAnalysis(JSONObject dayAnalysis, String channel) {
int clientId = dayAnalysis.getIntValue("client_id");
List<JSONObject> clientTrades = clientAnalysis.get(clientId);
if (clientTrades == null) {
clientTrades = new ArrayList<>();
clientAnalysis.put(clientId, clientTrades);
}
Date tradeDate = dayAnalysis.getDate("trade_date");
BigDecimal total = dayAnalysis.getBigDecimal("total");
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel + "_rate_value");
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal thirdPartyPaymentCharge = getThirdPartyCharge(channel, total);
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);
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);
item.put("gross_amount", gross);
BigDecimal totalCharge = item.getBigDecimal("total_charge").add(dayCharge);
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);
Date from = item.getDate("date_from");
Date to = item.getDate("date_to");
from = from.before(tradeDate) ? from : tradeDate;
to = to.after(tradeDate) ? to : tradeDate;
item.put("date_from", from);
item.put("date_to", to);
return this;
}
}
JSONObject item = new JSONObject();
item.put("year", year);
item.put("month", month);
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("org_charge", orgCharge);
item.put("channel", channel);
item.put("net_charge", netCharge);
item.put("commission_type",commissionType);
clientTrades.add(item);
return this;
}
public JSONObject totalCommission() {
JSONObject result = new JSONObject();
result.put("org_id", orgId);
result.put("year", year);
result.put("month", month);
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("channel", channel);
result.put("commission_type",commissionType);
return result;
}
public List<JSONObject> getCommissionDetails(String recordId) {
List<JSONObject> list = new ArrayList<>();
for (Map.Entry<Integer, List<JSONObject>> entry : clientAnalysis.entrySet()) {
int clientId = entry.getKey();
for (JSONObject item : entry.getValue()) {
item.put("client_id", clientId);
item.put("record_id", recordId);
list.add(item);
}
}
return list;
}
public CityPartnerSeniorCommissionAnalysis attachNetCommissionAnalysis(JSONObject dayAnalysis, String channel) {
int clientId = dayAnalysis.getIntValue("client_id");
List<JSONObject> clientTrades = clientAnalysis.get(clientId);
if (clientTrades == null) {
clientTrades = new ArrayList<>();
clientAnalysis.put(clientId, clientTrades);
}
Date tradeDate = dayAnalysis.getDate("trade_date");
BigDecimal total = dayAnalysis.getBigDecimal("total");
BigDecimal dayRate = dayAnalysis.getBigDecimal(channel + "_rate_value");
BigDecimal dayCharge = total.multiply(dayRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal royalpayCharge = total.multiply(rate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
BigDecimal thirdPartyPaymentCharge = getThirdPartyCharge(channel, total);
BigDecimal netCharge = royalpayCharge.subtract(thirdPartyPaymentCharge);
BigDecimal orgCharge = netCharge.multiply(orgRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
totalGrossAmount = totalGrossAmount.add(total);
totalChargeSum = totalChargeSum.add(dayCharge);
totalRoyalPayCharge = totalRoyalPayCharge.add(royalpayCharge);
totalOrgChargeSum = totalOrgChargeSum.add(orgCharge);
totalnetCharge = totalnetCharge.add(netCharge);
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);
item.put("gross_amount", gross);
BigDecimal totalCharge = item.getBigDecimal("total_charge").add(dayCharge);
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);
Date from = item.getDate("date_from");
Date to = item.getDate("date_to");
from = from.before(tradeDate) ? from : tradeDate;
to = to.after(tradeDate) ? to : tradeDate;
item.put("date_from", from);
item.put("date_to", to);
return this;
}
}
JSONObject item = new JSONObject();
item.put("year", year);
item.put("month", month);
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("org_charge", orgCharge);
item.put("channel", channel);
item.put("net_charge", netCharge);
clientTrades.add(item);
return this;
}
private BigDecimal getThirdPartyCharge(String channel, BigDecimal total) {
BigDecimal thirdPartyPaymentCharge = BigDecimal.ZERO;
switch (channel) {
case "alipay":
thirdPartyPaymentCharge = total.multiply(alipayChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
case "wechat":
thirdPartyPaymentCharge = total.multiply(wechatChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
case "jd":
thirdPartyPaymentCharge = total.multiply(jdChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
case "alipayonline":
thirdPartyPaymentCharge = total.multiply(alipayonlineChargeRate).divide(CommonConsts.HUNDRED, 2, RoundingMode.HALF_UP);
break;
default:
break;
}
return thirdPartyPaymentCharge;
}
}

@ -39,5 +39,12 @@ public interface CityPartnerPrizeService {
List<JSONObject> getAgentPrizeInfoList(String monthStr);
void generateSenior(String monthStr);
List<JSONObject> querySenior(JSONObject param);
JSONObject getSenior(String monthStr, String orgId);
}

@ -1,27 +1,5 @@
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.CityPartnerCommissionAnalysis;
import au.com.royalpay.payment.manage.citypartner.beans.ReferrerCommissionAnalysis;
@ -32,12 +10,38 @@ 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;
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.Collections;
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;
/**
* Created by yixian on 2017-03-08.
*/
@ -61,6 +65,10 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
private FinancialReferrerCommissionMapper financialReferrerCommissionMapper;
@Resource
private SysConfigManager sysConfigManager;
@Resource
private FinancialSeniorPartnerCommissionMapper financialSeniorPartnerCommissionMapper;
@Resource
private FinancialSeniorPartnerCommissionDetailMapper financialSeniorPartnerCommissionDetailMapper;
@Override
public List<JSONObject> listAvailableMonths(String year) {
@ -75,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);
}
@ -223,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);
@ -236,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;
}
@ -249,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");
@ -279,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");
@ -299,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()) {
@ -314,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();
}
@ -556,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");
@ -584,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();
@ -623,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);
@ -700,4 +714,80 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
return financialAgentCommissionMapper.list(year, month);
}
@Override
@Transactional
public void generateSenior(String monthStr) {
List<String> seniorOrgs = orgMapper.listSeniorOrgId(0);
if (CollectionUtils.isEmpty(seniorOrgs)) {
return;
}
Date mon = checkMonth(monthStr);
Calendar monthCal = Calendar.getInstance();
monthCal.setTime(mon);
int year = monthCal.get(Calendar.YEAR);
int month = monthCal.get(Calendar.MONTH) + 1;
JSONObject sysConfig = sysConfigManager.getSysConfig();
BigDecimal rate = sysConfig.getBigDecimal("senior_charge_rate").divide(CommonConsts.HUNDRED);
if (rate == null) {
rate = new BigDecimal("0.0006");
}
Date now = new Date();
financialSeniorPartnerCommissionMapper.clearData(year, month);
BigDecimal finalRate = rate;
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);
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
public List<JSONObject> querySenior(JSONObject param) {
Date mon = checkMonth(param.getString("monthStr"));
Calendar monthCal = Calendar.getInstance();
monthCal.setTime(mon);
int year = monthCal.get(Calendar.YEAR);
int month = monthCal.get(Calendar.MONTH) + 1;
List<String> orgs = orgMapper.listSeniorOrgId(param.getIntValue("org_id"));
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;
}
@Override
public JSONObject getSenior(String monthStr, String orgId) {
Date monthDate = parseMonth(monthStr);
Calendar monthCal = Calendar.getInstance();
monthCal.setTime(monthDate);
int year = monthCal.get(Calendar.YEAR);
int month = monthCal.get(Calendar.MONTH) + 1;
return financialSeniorPartnerCommissionMapper.find(year, month, orgId);
}
}

@ -271,4 +271,23 @@ public class CityPartnerPrizeController {
result.put("partner_info_list", partnerInfos);
return result;
}
@RequestMapping(value = "/senior/generate", method = RequestMethod.POST)
public void generateSenior(@RequestBody JSONObject param) {
String month = param.getString("month");
cityPartnerPrizeService.generate(month);
}
@RequestMapping(value = "/senior/{orgId}", method = RequestMethod.GET)
public void findOne(@RequestParam String monthStr, @PathVariable String orgId) {
cityPartnerPrizeService.getSenior(monthStr,orgId);
}
@RequestMapping(value = "/senior/{orgId}/details", method = RequestMethod.GET)
public List<JSONObject> findDetail(@RequestParam String monthStr, @PathVariable String orgId) {
JSONObject params = new JSONObject();
params.put("monthStr",monthStr);
params.put("org_id",orgId);
return cityPartnerPrizeService.querySenior(params);
}
}

@ -28,4 +28,8 @@ public interface FinancialPartnerCommissionMapper {
JSONObject getTotalPartnerCharge(@Param("year") int year, @Param("month") int month);
List<JSONObject> find(@Param("year") int year, @Param("month") int month, @Param("org_id") String orgId);
List<JSONObject> analysisSenior(@Param("year") int year, @Param("month")int month,@Param("orgIds") List<String> orgIds);
JSONObject analysisSeniorForGenerate(@Param("year") int year, @Param("month")int month,@Param("orgIds") List<String> orgIds);
}

@ -0,0 +1,30 @@
package au.com.royalpay.payment.manage.mappers.financial;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.alibaba.fastjson.JSONObject;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
/**
* Created by yixian on 2017-03-08.
*/
@AutoMapper(tablename = "financial_senior_partner_commission_detail", pkName = "id")
public interface FinancialSeniorPartnerCommissionDetailMapper {
@AutoSql(type = SqlType.DELETE)
void clearData(@Param("year") int year, @Param("month") int month,@Param("commission_type") int commission_type);
@AutoSql(type = SqlType.INSERT)
void save(JSONObject detail);
List<JSONObject> listDetails(@Param("record_id") String recordId);
List<JSONObject> listDetailsByRecordIds(List<String> recordId);
@AutoSql(type = SqlType.SELECT)
List<JSONObject> listDetailByMonth(@Param("year") int year, @Param("month") int month);
}

@ -0,0 +1,26 @@
package au.com.royalpay.payment.manage.mappers.financial;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.alibaba.fastjson.JSONObject;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
/**
* Created by yixian on 2017-03-08.
*/
@AutoMapper(tablename = "financial_senior_partner_commission", pkName = "id")
public interface FinancialSeniorPartnerCommissionMapper {
@AutoSql(type = SqlType.DELETE)
void clearData(@Param("year") int year, @Param("month") int month);
@AutoSql(type = SqlType.INSERT)
void save(JSONObject commissionAnalysis);
@AutoSql(type = SqlType.SELECT)
JSONObject find(@Param("year") int year, @Param("month") int month, @Param("org_id") String orgId);
}

@ -42,9 +42,15 @@ public interface OrgMapper {
@AdvanceSelect(addonWhereClause = "is_valid=1 AND parent_org_id is null")
List<JSONObject> listAllOrgs();
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1 AND senior_parent_org_id=0")
List<JSONObject> listSeniorOrgs();
JSONObject findOrgByBDId(@Param("bd_id") String bd_id);
PageList<JSONObject> listOrgWithPages(JSONObject paraams, PageBounds order);
List<JSONObject> listOrgAndChild(@Param("org_id") int org_id);
List<String> listSeniorOrgId(@Param("senior_parent_org_id") int senior_parent_org_id);
}

@ -43,6 +43,8 @@ public class OrgInfo {
private Double min_alipayonline_rate;
private Double min_hf_rate;
private String state;
private String senior_parent_org_id;
public JSONObject toJsonParam() {
JSONObject param = new JSONObject();
@ -55,15 +57,19 @@ public class OrgInfo {
if (StringUtils.isNotBlank(search_text)) {
param.put("search_text", search_text);
}
if (type != null){
if (type != null) {
param.put("type", type);
}
if (StringUtils.isNotBlank(parent_org_id)){
if (StringUtils.isNotBlank(parent_org_id)) {
param.put("parent_org_id", parent_org_id);
}
if (StringUtils.isNotBlank(org_id)){
if (StringUtils.isNotBlank(org_id)) {
param.put("org_id", org_id);
}
if (StringUtils.isNotBlank(senior_parent_org_id)) {
param.put("senior_parent_org_id", senior_parent_org_id);
}
return param;
}
@ -310,4 +316,11 @@ public class OrgInfo {
public void setState(String state) {
this.state = state;
}
public String getSenior_parent_org_id() {
return senior_parent_org_id;
}
public void setSenior_parent_org_id(String senior_parent_org_id) {
this.senior_parent_org_id = senior_parent_org_id;
}
}

@ -11,6 +11,8 @@ import java.util.List;
public interface OrgManager {
List<JSONObject> listOrgs(boolean detail);
List<JSONObject> listSeniorOrgs();
List<JSONObject> listOrgsWithChid(JSONObject manager,OrgInfo orgInfo);
List<JSONObject> listOrgAndChild(JSONObject manager);

@ -3,25 +3,25 @@ package au.com.royalpay.payment.manage.organizations.core.impls;
import au.com.royalpay.payment.manage.mappers.system.OrgMapper;
import au.com.royalpay.payment.manage.organizations.beans.OrgInfo;
import au.com.royalpay.payment.manage.organizations.core.OrgManager;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import com.alibaba.fastjson.JSONArray;
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 org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
/**
* Created by yixian on 2016-10-18.
*/
@ -36,6 +36,11 @@ public class OrgManagerImpl implements OrgManager {
return orgMapper.listOrgs(0,sort);
}
@Override
public List<JSONObject> listSeniorOrgs() {
return orgMapper.listSeniorOrgs();
}
@Override
public List<JSONObject> listOrgsWithChid(JSONObject manager,OrgInfo orgInfo) {
JSONObject params = new JSONObject();

@ -3,18 +3,26 @@ package au.com.royalpay.payment.manage.organizations.web;
import au.com.royalpay.payment.manage.organizations.beans.OrgInfo;
import au.com.royalpay.payment.manage.organizations.core.OrgManager;
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.manage.permission.manager.RequireManager;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.http.HttpUtils;
import com.alibaba.fastjson.JSONArray;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import com.alibaba.fastjson.JSONObject;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
/**
* Created by yixian on 2016-10-18.
@ -31,6 +39,12 @@ public class OrgManageController {
return orgManager.listOrgs(detail);
}
@RequestMapping(value = "/senior",method = RequestMethod.GET)
@RequireManager
public List<JSONObject> listSeniorOrgs() {
return orgManager.listSeniorOrgs();
}
@RequestMapping(value = "/orgChild",method = RequestMethod.GET)
@RequireManager
public List<JSONObject> listOrgsWithChid(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager,OrgInfo orgInfo) {

@ -38,4 +38,26 @@
INNER JOIN sys_org o ON o.org_id = c.org_id and o.type=0
WHERE c.year = #{year} AND c.month = #{month} and c.org_id=#{org_id}
</select>
<select id="analysisSenior" resultType="com.alibaba.fastjson.JSONObject">
select sum(c.gross_amount) gross_amount,c.org_id,o.name org_name from financial_partner_commission c left join sys_org o on c.org_id = o.org_id
where c.`year` =#{year} and c.`month` = #{month}
and c.org_id in
(<foreach collection="orgIds" item="item" separator=",">
#{item}
</foreach>)
group by c.org_id
</select>
<select id="analysisSeniorForGenerate" resultType="com.alibaba.fastjson.JSONObject">
select sum(gross_amount) gross_amount from financial_partner_commission
where `year` =#{year} and `month` = #{month}
and org_id in
(<foreach collection="orgIds" item="item" separator=",">
#{item}
</foreach>)
</select>
</mapper>

@ -70,4 +70,12 @@
</where>
</select>
<select id="listSeniorOrgId" resultType="java.lang.String">
select org_id from sys_org
where is_valid = 1
<if test="senior_parent_org_id > -1">
and senior_parent_org_id = #{senior_parent_org_id}
</if>
</select>
</mapper>

@ -93,6 +93,17 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
if (($scope.currentUser.role & parseInt('1000000000000', 2)) > 0 && $scope.currentUser.org_id) {
$scope.org.type = 0;
}
$scope.loadSeniorOrg = function () {
$http.get('/sys/orgs/senior').then(function (resp) {
$scope.seniorOrgs = resp.data;
var senior = {org_id:0,name:'I\'m Senior'}
var noop = {org_id:-1,name:'noop'}
$scope.seniorOrgs.unshift(noop);
$scope.seniorOrgs.unshift(senior);
})
};
$scope.loadSeniorOrg(1);
$scope.uploadLogo = function (file) {
if (file == null) {
return;
@ -294,7 +305,18 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
app.controller('newOrgCtrl', ['$scope', '$http', '$state', 'Upload', 'commonDialog','stateMap', function ($scope, $http, $state, Upload, commonDialog,stateMap) {
$scope.types = angular.copy(types);
$scope.commission_types = angular.copy(commission_types);
$scope.loadSeniorOrg = function () {
$http.get('/sys/orgs/senior').then(function (resp) {
$scope.seniorOrgs = resp.data;
var senior = {org_id:0,name:'I\'m Senior'}
var noop = {org_id:-1,name:'noop'}
$scope.seniorOrgs.unshift(noop);
$scope.seniorOrgs.unshift(senior);
})
};
$scope.loadSeniorOrg(1);
$scope.states = stateMap.configs();
$scope.uploadLogo = function (file) {
if (file == null) {
return;

@ -66,6 +66,16 @@
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="senior_parent_org_id">Senior Partner </label>
<div class="col-sm-8">
<select class="form-control" name="senior_parent_org_id" ng-model="org.senior_parent_org_id" id="senior_parent_org_id"
ng-options="seniorOrg.org_id as seniorOrg.name for seniorOrg in seniorOrgs">
</select>
</div>
</div>
<div class="form-group" ng-class="{'has-error':org_form.commission_type_0.$invalid && org_form.commission_type_0.$dirty}"
ng-show="org.type == 0 || ('1000000000000'|withRole)">
<label class="control-label col-sm-2" for="commission_type_0">Commission Type *</label>
@ -77,6 +87,9 @@
</select>
</div>
</div>
<div ng-if="org.type == 1">
<div class="form-group"
ng-class="{'has-error':org_form.rate_value.$invalid && org_form.rate_value.$dirty}">

@ -81,7 +81,15 @@
<div class="col-sm-8">
<select class="form-control" name="commission_type_0" required ng-model="org.commission_type" id="commission_type_0"
ng-options="commission_type.value as commission_type.label for commission_type in commission_types">
<option value="">Please Choose</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="senior_parent_org_id">Senior Partner </label>
<div class="col-sm-8">
<select class="form-control" name="senior_parent_org_id" ng-model="org.senior_parent_org_id" id="senior_parent_org_id"
ng-options="seniorOrg.org_id as seniorOrg.name for seniorOrg in seniorOrgs">
<option value="-1">noop</option>
</select>
</div>
</div>

@ -123,17 +123,21 @@ define(['angular','../../analysis/org/analysis-org'], function (angular) {
}]);
app.controller('orgCommissionMonthViewCtrl', ['$scope', 'monthData','$filter', function ($scope, monthData) {
app.controller('orgCommissionMonthViewCtrl', ['$scope', 'monthData','$http', function ($scope, monthData,$http) {
$scope.monthData = monthData.data;
$scope.ctrl = {};
$scope.commissionTypeMap = commissionTypeMap;
$scope.seniors = {};
$scope.active = function (log) {
if($scope.ctrl.activeLog && $scope.ctrl.activeLog.org_id==log.org_id){
$scope.ctrl.activeLog=null;
return;
}
$scope.ctrl.activeLog=log;
$http.get('/sys/citypartner_prizes/senior/'+log.org_id+'/details?monthStr='+$scope.monthData.monthstr).then(function (resp) {
$scope.seniors = resp.data;
if($scope.ctrl.activeLog && $scope.ctrl.activeLog.org_id==log.org_id){
$scope.ctrl.activeLog=null;
return;
}
$scope.ctrl.activeLog=log;
})
}
}]);
app.controller('orgCommissionOrgDetailCtrl', ['$scope', 'detail', function ($scope, detail) {

@ -28,9 +28,15 @@
<div class="col-xs-3 col-sm-3 nowrap">
Net Charge:{{detail.net_charge}}
</div>
<div class="col-xs-6 col-sm-6 nowrap">
<div class="col-xs-3 col-sm-3 nowrap">
City Partner Charge:{{detail.city_partner_charge}}
</div>
<div class="col-xs-3 col-sm-3 nowrap">
Own Charge:{{detail.own_charge}}
</div>
<div class="col-xs-12 col-sm-12 nowrap">
Senior Partner Charge:{{detail.senior_partner_charge}}
</div>
<div class="col-xs-3 ng-scope"
ng-if="detail.Alipay_gross_amount|| detail.Alipay_total_charge || detail.Alipay_royalpay_charge|| detail.Alipay_org_charge">

@ -81,6 +81,25 @@
</tr>
</tbody>
</table>
<table ng-if="seniors.length>0" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Rate</th>
<th>Org Name</th>
<th>Transaction Amount</th>
<th>Net Charge</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "senior in seniors" >
<td ng-bind="senior.org_rate"></td>
<td ng-bind="senior.org_name"></td>
<td ng-bind="senior.gross_amount"></td>
<td ng-bind="senior.net_charge"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>

@ -1,6 +1,7 @@
package au.com.royalpay.payment.manage.apps.core.impls;
import au.com.royalpay.payment.manage.analysis.core.WeekReporter;
import au.com.royalpay.payment.manage.citypartner.core.CityPartnerPrizeService;
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientConfigMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
@ -59,9 +60,9 @@ import cn.yixblog.platform.http.HttpRequestResult;
/**
* Created by wangning on 05/01/2018.
*/
@SpringBootTest
@ActiveProfiles({ "proxy", "alipay", "wechat", "jd", "bestpay" })
@RunWith(SpringRunner.class)
// @SpringBootTest
// @ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
// @RunWith(SpringRunner.class)
public class CustomerImpressionImplTest {
@Resource
private OrderMapper orderMapper;
@ -84,6 +85,8 @@ public class CustomerImpressionImplTest {
@Resource
private WeekReporter weekReporter;
@Resource
private CityPartnerPrizeService cityPartnerPrizeService;
@Test
public void redisQueue() {
@ -616,4 +619,9 @@ public class CustomerImpressionImplTest {
}
@Test
public void zxcs(){
cityPartnerPrizeService.generateSenior("2018-02");
}
}
Loading…
Cancel
Save