add senior partner prize

master
kira 6 years ago
parent 5a218b2090
commit d1b3de8b87

@ -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);
}
}

@ -282,4 +282,12 @@ public class CityPartnerPrizeController {
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);
}
}

@ -30,4 +30,6 @@ public interface FinancialPartnerCommissionMapper {
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);
}

@ -16,18 +16,11 @@ import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
@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, @Param("commission_type") int commission_type);
void clearData(@Param("year") int year, @Param("month") int month);
@AutoSql(type = SqlType.INSERT)
void save(JSONObject commissionAnalysis);
List<Integer> listAvailableMonths(@Param("year") int year);
List<JSONObject> listWithOrgInfo(@Param("year") int year, @Param("month") int month);
List<JSONObject> list(@Param("year") int year, @Param("month") int month);
JSONObject getTotalPartnerCharge(@Param("year") int year, @Param("month") int month);
@AutoSql(type = SqlType.SELECT)
JSONObject find(@Param("year") int year, @Param("month") int month, @Param("org_id") String orgId);
}

@ -40,12 +40,24 @@
</select>
<select id="analysisSenior" resultType="com.alibaba.fastjson.JSONObject">
select sum(gross_amount) gross_amount,org_id from financial_partner_commission
where `year` =#{year} and `month` = #{month}
and org_id in
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 org_id
#{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>

@ -74,11 +74,8 @@
<select id="listSeniorOrgId" resultType="java.lang.String">
select org_id from sys_org
where is_valid = 1
<if test="senior_parent_org_id!=0">
<if test="senior_parent_org_id > -1">
and senior_parent_org_id = #{senior_parent_org_id}
</if>
<if test="senior_parent_org_id==0">
and senior_parent_org_id !=0
</if>
</select>
</mapper>

@ -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;
@ -23,8 +24,12 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.File;
@ -54,9 +59,9 @@ import cn.yixblog.platform.http.HttpRequestResult;
/**
* Created by wangning on 05/01/2018.
*/
// @SpringBootTest
// @ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
// @RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
@RunWith(SpringRunner.class)
public class CustomerImpressionImplTest {
@Resource
private OrderMapper orderMapper;
@ -79,6 +84,8 @@ public class CustomerImpressionImplTest {
@Resource
private WeekReporter weekReporter;
@Resource
private CityPartnerPrizeService cityPartnerPrizeService;
@Test
public void redisQueue() {
@ -531,4 +538,9 @@ public class CustomerImpressionImplTest {
return result;
}
@Test
public void zxcs(){
cityPartnerPrizeService.generateSenior("2018-02");
}
}
Loading…
Cancel
Save