bd提成下载&bd提成查询优化

master
yangkai 6 years ago
parent 28ab73c425
commit 6b68f0c563

@ -8,6 +8,8 @@ import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletResponse;
/**
* Created by yixian on 2017-02-07.
*/
@ -40,4 +42,6 @@ public interface BDPrizeService {
void deleteCommConfig(String config_id);
void updateBdKpiConfig(List<JSONObject> configs, JSONObject manager)throws ParseException;
void exportCommissionMonth(String month, HttpServletResponse response) throws Exception;
}

@ -5,12 +5,7 @@ import au.com.royalpay.payment.manage.bdprize.core.BDPrizeService;
import au.com.royalpay.payment.manage.bdprize.support.BDPrizeCalculator;
import au.com.royalpay.payment.manage.bdprize.support.impls.BDPrizeCalculatorDefaultImpl;
import au.com.royalpay.payment.manage.bdprize.support.impls.DefaultClientWithBDAwayDeterminor;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDCommissionConfigMapper;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDConfigMapper;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDPrizeDetailMapper;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDPrizeLogMapper;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDPrizeRecordMapper;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDRateConfigMapper;
import au.com.royalpay.payment.manage.mappers.financial.*;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper;
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
@ -27,6 +22,11 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -44,6 +45,7 @@ import java.util.GregorianCalendar;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
/**
* Created by yixian on 2017-02-07.
@ -74,6 +76,8 @@ public class BDPrizeServiceImpl implements BDPrizeService {
@Resource
private FinancialBDCommissionConfigMapper financialBDCommissionConfigMapper;
@Resource
private FinancialLeaderPrizeLogMapper financialLeaderPrizeLogMapper;
@Value("${app.backup-app:false}")
private boolean backupSystem;
@ -239,54 +243,88 @@ public class BDPrizeServiceImpl implements BDPrizeService {
// cityPrizeLog.put("total_prize", total_prize);
// }
// report.put("cityPrizeLogs", cityPrizeLog);
List<JSONObject> leaderPrizeLog = financialLeaderPrizeLogMapper.listLeaderPrizeLog(report.getString("record_id"));
if (leaderPrizeLog.size() > 0) {
for (JSONObject prizeLog : leaderPrizeLog) {
if (prizeLog.getIntValue("bd_type") == 3) {
report.put("sydneyPrizeLog", prizeLog);
}
if (prizeLog.getIntValue("bd_type") == 4) {
report.put("directPrizeLogs", prizeLog);
}
if (prizeLog.getIntValue("bd_type") == 5) {
report.put("ngDepartmentPrizeLog", prizeLog);
}
}
return report;
}
//bd_type=3 悉尼分公司经理 悉尼销售组和大客户组流水提成
JSONObject sydneyPrizeLog = new JSONObject();
BigDecimal sydneyAmount = transactionMapper.TotalAmountForSydneyGMPrize(monthDate.getYear(), monthDate.getMonthOfYear());
sydneyPrizeLog.put("total_amount",sydneyAmount);
JSONObject sydneyGMRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, sydneyAmount.toString(), 3);
if (sydneyGMRate == null) {
sydneyPrizeLog.put("total_prize", 0.00);
} else {
BigDecimal sydney_commission_rate = new BigDecimal(sydneyGMRate.getString("commission_rate"));
BigDecimal total_prize = sydneyAmount.multiply(sydney_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
sydneyPrizeLog.put("total_prize", total_prize);
if (!locker.lock(report.getString("record_id"), 300_000)) {
throw new ServerErrorException("Processing task, wait for a moment");
}
report.put("sydneyPrizeLog", sydneyPrizeLog);
//COO & NJ commission
JSONObject params = new JSONObject();
params.put("begin", TimeZoneUtils.beginDate(TimeZoneUtils.getFirstDay(monthDate.toString())));
params.put("end", TimeZoneUtils.getPerFirstDayOfMonth(TimeZoneUtils.getLastDay(monthDate.toString())));
BigDecimal totalprize = transactionAnalysisMapper.analysisTotalAmount(params);
try {
List<JSONObject> prizeLogList = new ArrayList<>();
JSONObject sydneyPrizeLog = new JSONObject();
BigDecimal sydneyAmount = transactionMapper.TotalAmountForSydneyGMPrize(monthDate.getYear(), monthDate.getMonthOfYear());
sydneyPrizeLog.put("total_amount",sydneyAmount);
sydneyPrizeLog.put("bd_type", 3);
JSONObject sydneyGMRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, sydneyAmount.toString(), 3);
if (sydneyGMRate == null) {
sydneyPrizeLog.put("total_prize", 0.00);
} else {
BigDecimal sydney_commission_rate = new BigDecimal(sydneyGMRate.getString("commission_rate"));
BigDecimal total_prize = sydneyAmount.multiply(sydney_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
sydneyPrizeLog.put("total_prize", total_prize);
}
report.put("sydneyPrizeLog", sydneyPrizeLog);
prizeLogList.add(sydneyPrizeLog);
//COO & NJ commission
JSONObject params = new JSONObject();
params.put("begin", TimeZoneUtils.beginDate(TimeZoneUtils.getFirstDay(monthDate.toString())));
params.put("end", TimeZoneUtils.getPerFirstDayOfMonth(TimeZoneUtils.getLastDay(monthDate.toString())));
BigDecimal totalprize = transactionAnalysisMapper.analysisTotalAmount(params);
JSONObject directPrizeLogs = new JSONObject();
directPrizeLogs.put("total_amount", totalprize);
directPrizeLogs.put("bd_type", 4);
JSONObject rate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, totalprize.toString(), 4);
if (rate == null) {
directPrizeLogs.put("total_prize", 0.00);
} else {
BigDecimal _commission_rate = new BigDecimal(rate.getString("commission_rate"));
BigDecimal _total_amount = new BigDecimal(directPrizeLogs.getString("total_amount"));
BigDecimal total_prize = _total_amount.multiply(_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
directPrizeLogs.put("total_prize", total_prize);
}
report.put("directPrizeLogs", directPrizeLogs);
prizeLogList.add(directPrizeLogs);
JSONObject ngDepartmentPrizeLog = new JSONObject();
ngDepartmentPrizeLog.put("total_amount", totalprize);
ngDepartmentPrizeLog.put("bd_type", 5);
JSONObject ngRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, totalprize.toString(), 5);
if (ngRate == null) {
ngDepartmentPrizeLog.put("total_prize", 0.00);
} else {
BigDecimal ng_commission_rate = new BigDecimal(ngRate.getString("commission_rate"));
BigDecimal ng_total_prize = totalprize.multiply(ng_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
ngDepartmentPrizeLog.put("total_prize", ng_total_prize);
}
report.put("ngDepartmentPrizeLog", ngDepartmentPrizeLog);
prizeLogList.add(ngDepartmentPrizeLog);
JSONObject directPrizeLogs = new JSONObject();
directPrizeLogs.put("total_amount", totalprize);
JSONObject rate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, totalprize.toString(), 4);
if (rate == null) {
directPrizeLogs.put("total_prize", 0.00);
} else {
BigDecimal _commission_rate = new BigDecimal(rate.getString("commission_rate"));
BigDecimal _total_amount = new BigDecimal(directPrizeLogs.getString("total_amount"));
BigDecimal total_prize = _total_amount.multiply(_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
directPrizeLogs.put("total_prize", total_prize);
for (JSONObject prizeLog : prizeLogList) {
prizeLog.put("record_id", report.getString("record_id"));
prizeLog.put("create_time", new Date());
financialLeaderPrizeLogMapper.save(prizeLog);
}
return report;
} finally {
locker.unlock(report.getString("record_id"));
}
report.put("directPrizeLogs", directPrizeLogs);
JSONObject ngDepartmentPrizeLog = new JSONObject();
ngDepartmentPrizeLog.put("total_amount", totalprize);
JSONObject ngRate = financialBDCommissionConfigMapper.findCurrentCommissionRate(month, totalprize.toString(), 5);
if (ngRate == null) {
ngDepartmentPrizeLog.put("total_prize", 0.00);
} else {
BigDecimal ng_commission_rate = new BigDecimal(ngRate.getString("commission_rate"));
BigDecimal ng_total_prize = totalprize.multiply(ng_commission_rate.divide(percent)).setScale(2, BigDecimal.ROUND_DOWN);
ngDepartmentPrizeLog.put("total_prize", ng_total_prize);
}
report.put("ngDepartmentPrizeLog", ngDepartmentPrizeLog);
return report;
}
@Override
@ -469,4 +507,136 @@ public class BDPrizeServiceImpl implements BDPrizeService {
financialBDConfigMapper.updateBDConfig(config);
}
}
@Override
public void exportCommissionMonth(String month, HttpServletResponse resp) throws Exception {
OutputStream ous = null;
JSONObject report = findReport(month);
if (report != null) {
List<JSONObject> logs = (List<JSONObject>) report.get("logs");
resp.setContentType("application/octet-stream;");
resp.addHeader("Content-Disposition", "attachment; filename=" + "BD_Commission_Info_" + month + ".xls");
ous = resp.getOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
Cell cell = null;
HSSFFont font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 10);
CellStyle titleStyle = wb.createCellStyle();
titleStyle.setFont(font);
HSSFCellStyle style = wb.createCellStyle();
//设置背景颜色
style.setFillForegroundColor(HSSFColor.RED.index);
//solid 填充 foreground 前景色
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
Sheet sheet = wb.createSheet("BD_Commission_Info_" + month);
sheet.setDefaultColumnWidth(20);
int rowNum = 0;
Row row = sheet.createRow(rowNum);
//bd and manager
String[] BDTitle = {"BD Name","KPI", "BD Level", "Transaction Amount", "Total Commission","Send Commission", "Hold prize", "Prize Type"};
for (int i = 0; i < BDTitle.length; i++) {
cell = row.createCell(i, Cell.CELL_TYPE_STRING);
cell.setCellStyle(titleStyle);
cell.setCellValue(BDTitle[i]);
}
for (JSONObject log : logs) {
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(log.getString("bd_name"));
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(log.getBigDecimal("kpi_amount")==null?BigDecimal.ZERO.toPlainString():log.getBigDecimal("kpi_amount").toPlainString());
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(financialBdLevel(log.getIntValue("bd_level")));
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(log.getBigDecimal("total_amount").toPlainString());
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(log.getBigDecimal("total_prize").toPlainString());
row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(log.getBigDecimal("send_prize").toPlainString());
row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(log.getBigDecimal("hold_prize").toPlainString());
if (log.getIntValue("prize_type") == 0) {
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue("BD");
}
if (log.getIntValue("prize_type") == 1) {
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue("Group");
}
if (!log.getBoolean("is_valid")) {
for (int i = 0; i <= 7; i++) {
row.getCell(i).setCellStyle(style);
}
}
}
//analysis
String[] analysisTitle = {"month", "Total Commission", "Total Send", "Total Hold", "Total Fund"};
row = sheet.createRow(++rowNum);
for (int i = 0; i < analysisTitle.length; i++) {
cell = row.createCell(i, Cell.CELL_TYPE_STRING);
cell.setCellStyle(titleStyle);
cell.setCellValue(analysisTitle[i]);
}
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(month);
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(report.getBigDecimal("total_prize").toPlainString());
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(report.getBigDecimal("total_send_prize").toPlainString());
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(report.getBigDecimal("total_hold_prize").toPlainString());
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(report.getBigDecimal("total_donation").toPlainString());
//channel
String[] channelTitle = {"channel", "BD Total Commission", "BD Total Send", "BD Total Hold", "BD Total Fund"};
row = sheet.createRow(++rowNum);
for (int i = 0; i < channelTitle.length; i++) {
cell = row.createCell(i, Cell.CELL_TYPE_STRING);
cell.setCellStyle(titleStyle);
cell.setCellValue(channelTitle[i]);
}
for (String channel: channels) {
JSONObject channelReport = report.getJSONObject(channel + "Report");
if (channelReport != null) {
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(channel);
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(channelReport.getBigDecimal("total_prize").toPlainString());
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(channelReport.getBigDecimal("total_send_prize").toPlainString());
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(channelReport.getBigDecimal("total_hold_prize").toPlainString());
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(channelReport.getBigDecimal("total_donation").toPlainString());
}
}
//Sydney GM & COO & NJ commission
String[] GMTitle = {"name", "Transaction Amount", "Total Commission"};
row = sheet.createRow(++rowNum);
for (int i = 0; i < GMTitle.length; i++) {
cell = row.createCell(i, Cell.CELL_TYPE_STRING);
cell.setCellStyle(titleStyle);
cell.setCellValue(GMTitle[i]);
}
JSONObject sydneyPrizeLog = report.getJSONObject("sydneyPrizeLog");
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue("Sydney GM");
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(sydneyPrizeLog.getBigDecimal("total_amount").toPlainString());
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(sydneyPrizeLog.getBigDecimal("total_prize").toPlainString());
JSONObject ngDepartmentPrizeLog = report.getJSONObject("ngDepartmentPrizeLog");
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue("NJ Department");
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(ngDepartmentPrizeLog.getBigDecimal("total_amount").toPlainString());
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(ngDepartmentPrizeLog.getBigDecimal("total_prize").toPlainString());
JSONObject directPrizeLogs = report.getJSONObject("directPrizeLogs");
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue("COO");
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(directPrizeLogs.getBigDecimal("total_amount").toPlainString());
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(directPrizeLogs.getBigDecimal("total_prize").toPlainString());
wb.write(ous);
ous.flush();
}
}
private String financialBdLevel (int level) {
switch (level) {
case 0:
return "Leader";
case 1:
return "Junior";
case 2:
return "Intermediate";
case 3:
return "Senior";
default:
return "Unknown";
}
}
}

@ -15,10 +15,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
/**
* Created by yixian on 2017-02-07.
@ -97,4 +99,9 @@ public class BDPrizeController {
public void updatKpiConfig(@PathVariable String month , @RequestBody List<JSONObject> info , @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) throws ParseException {
bdPrizeService.updateBdKpiConfig(info,manager);
}
@ManagerMapping(value = "/commission/export/{month}",method = RequestMethod.GET, role = {ManagerRole.SALES_MANAGER, ManagerRole.FINANCIAL_STAFF,ManagerRole.DIRECTOR, ManagerRole.ADMIN})
public void exportCommissionMonth(@PathVariable String month, HttpServletResponse response) throws Exception {
bdPrizeService.exportCommissionMonth(month, response);
}
}

@ -0,0 +1,19 @@
package au.com.royalpay.payment.manage.mappers.financial;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@AutoMapper(tablename = "financial_leader_prize_log", pkName = "leader_prize_log")
public interface FinancialLeaderPrizeLogMapper {
@AutoSql(type = SqlType.SELECT)
List<JSONObject> listLeaderPrizeLog(@Param(value = "record_id") String record_id);
@AutoSql(type = SqlType.INSERT)
void save(JSONObject prizeLog);
}

@ -11,7 +11,8 @@
r.*,l.kpi_amount,
sum(total_prize) total_prize,
sum(send_prize) total_send_prize,
sum(total_donation) total_donation
sum(total_donation) total_donation,
sum(hold_prize) total_hold_prize
FROM financial_bd_prize_records r
INNER JOIN financial_bd_prize_log l ON l.record_id = r.record_id
WHERE r.month = #{month}
@ -20,7 +21,8 @@
SELECT
sum(total_prize) total_prize,
sum(send_prize) total_send_prize,
sum(total_donation) total_donation
sum(total_donation) total_donation,
sum(hold_prize) total_hold_prize
FROM financial_bd_prize_log
WHERE record_id = #{record_id}
AND channel = #{channel}

@ -141,6 +141,9 @@ define(['angular', '../../analysis/bd/analysis-bd'], function (angular) {
}
}
})
};
$scope.exportCommission = function (monModal) {
location.href = '/sys/bd_prize/commission/export/' + monModal;
}
}]);
app.controller('bdRateConfigCtrl', ['$scope', '$http', 'rates', function ($scope, $http, rates) {

@ -49,18 +49,20 @@
</div>
<div class="box-body">
<div class="row">
<div class="col-xs-2" ng-repeat="mon in months">
<div class="col-xs-2" style="text-align: center" ng-repeat="mon in months">
<a ng-if="hasReport(mon) && (('10000000000000'|withRole)||('1000'|withRole))">
<h2 ROLE="button" class="text-success" ui-sref=".month_report({month:mon})" ng-bind="mon.substring(5,7)"></h2>
<span class="fa fa-edit btn" ng-click="editCommissionConfig(mon)">Commission</span>
<span class="fa fa-edit btn" ng-click="editCommissionConfig(mon)"></span>
<span class="fa fa-download btn" ng-click="exportCommission(mon)"></span>
</a>
<a ng-if="hasReport(mon) && ('100'|withRole) && (!('1000'|withRole))">
<h2 ROLE="button" class="text-success" ui-sref=".bd_detail({month:mon})" ng-bind="mon.substring(5,7)"></h2>
<span class="fa fa-edit btn" ng-click="editCommissionConfig(mon)">Commission</span>
<span class="fa fa-edit btn" ng-click="editCommissionConfig(mon)"></span>
<span class="fa fa-download btn" ng-click="exportCommission(mon)"></span>
</a>
<a ng-if="!hasReport(mon)">
<h2 ROLE="button" class="text-gray" ng-bind="mon.substring(5,7)"></h2>
<span class="fa fa-edit btn" ng-click="editCommissionConfig(mon)">Commission</span>
<span class="fa fa-edit btn" ng-click="editCommissionConfig(mon)"></span>
</a>
</div>
</div>

Loading…
Cancel
Save