Merge remote-tracking branch 'origin/develop' into develop

master
yixian 6 years ago
commit b8d2303443

@ -44,4 +44,8 @@ public interface BDPrizeService {
void updateBdKpiConfig(List<JSONObject> configs, JSONObject manager)throws ParseException; void updateBdKpiConfig(List<JSONObject> configs, JSONObject manager)throws ParseException;
void exportCommissionMonth(String month, HttpServletResponse response) throws Exception; void exportCommissionMonth(String month, HttpServletResponse response) throws Exception;
void exportCommissionDetail(String month, String managerId, HttpServletResponse response);
List<JSONObject> findCommissionList(JSONObject manager);
} }

@ -20,6 +20,7 @@ import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order; import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFCellStyle;
@ -27,6 +28,7 @@ import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -34,6 +36,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
@ -625,6 +628,66 @@ public class BDPrizeServiceImpl implements BDPrizeService {
} }
} }
@Override
public void exportCommissionDetail(String month, String managerId, HttpServletResponse resp) {
try {
Date mon = DateUtils.parseDate(month, new String[]{"yyyy-MM"});
month = DateFormatUtils.format(mon, "yyyy-MM");
} catch (ParseException e) {
throw new BadRequestException("Invalid Month");
}
JSONObject report = financialBDPrizeRecordMapper.findByMonth(month);
if (report == null) {
throw new BadRequestException("Report not created");
}
List<JSONObject> bdLogs = financialBDPrizeDetailMapper.findCommissionDetailById(report.getString("record_id"), managerId);
OutputStream ous = null;
try {
resp.setContentType("application/octet-stream;");
resp.addHeader("Content-Disposition",
"attachment; filename=" + "BD_COMMISSION_" + month + ".xlsx");
ous = resp.getOutputStream();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
int rowNum = 0;
Row row = sheet.createRow(rowNum);
String[] title = {"Client Moniker", "Order Date Range", "Client Rate", "Client Source", "Init Months", "Transaction", "Coefficient", "BD Rate",
"Commission", "Channel"};
for (int i = 0; i < title.length; i++) {
row.createCell(i, Cell.CELL_TYPE_STRING).setCellValue(title[i]);
}
for (JSONObject bdlog : bdLogs) {
row = sheet.createRow(++rowNum);
bdlog.put("order_date_from", DateFormatUtils.format(bdlog.getDate("order_date_from"), "dd/MMM/yyyy", RequestEnvironment.getLocale()));
bdlog.put("order_date_to", DateFormatUtils.format(bdlog.getDate("order_date_to"), "dd/MMM/yyyy", RequestEnvironment.getLocale()));
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("client_moniker"));
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("order_date_from") + "~" + bdlog.getString("order_date_to"));
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("rate_value") + "%");
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(financialClientSource(bdlog.getIntValue("source")));
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("client_create_months"));
row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("total_transaction"));
row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("coefficient"));
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("bd_rate") + "%");
row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("prize_value"));
row.createCell(9, Cell.CELL_TYPE_STRING).setCellValue(bdlog.getString("channel"));
}
wb.write(ous);
ous.flush();
IOUtils.closeQuietly(ous);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public List<JSONObject> findCommissionList(JSONObject manager) {
if (ManagerRole.BD_USER.hasRole(manager.getIntValue("role"))) {
return financialBDPrizeRecordMapper.getReportByManagerId(manager.getString("manager_id"));
}
return null;
}
private String financialBdLevel (int level) { private String financialBdLevel (int level) {
switch (level) { switch (level) {
case 0: case 0:
@ -639,4 +702,18 @@ public class BDPrizeServiceImpl implements BDPrizeService {
return "Unknown"; return "Unknown";
} }
} }
private String financialClientSource(int source) {
switch (source) {
case 1:
return "BD";
case 2:
return "Apply";
case 3:
return "Distribute";
default:
return "Unknown";
}
}
} }

@ -104,4 +104,19 @@ public class BDPrizeController {
public void exportCommissionMonth(@PathVariable String month, HttpServletResponse response) throws Exception { public void exportCommissionMonth(@PathVariable String month, HttpServletResponse response) throws Exception {
bdPrizeService.exportCommissionMonth(month, response); bdPrizeService.exportCommissionMonth(month, response);
} }
@ManagerMapping(value = "/commission/export/{month}/bd_users/{managerId}", method = RequestMethod.GET, role = {ManagerRole.FINANCIAL_STAFF})
public void exportCommissionDetail(@PathVariable String month, @PathVariable String managerId, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse response) {
bdPrizeService.exportCommissionDetail(month, managerId, response);
}
@ManagerMapping(value = "/commission/personal/bd_user", method = RequestMethod.GET, role = {ManagerRole.BD_USER})
public List<JSONObject> getCommissionList(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
return bdPrizeService.findCommissionList(manager);
}
@ManagerMapping(value = "/commission/export/{month}/bd_users", method = RequestMethod.GET, role = {ManagerRole.BD_USER})
public void exportCommissionBdUserDetail(@PathVariable String month, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse response) {
bdPrizeService.exportCommissionDetail(month, manager.getString("manager_id"), response);
}
} }

@ -21,4 +21,6 @@ public interface FinancialBDPrizeDetailMapper {
List<JSONObject> listDetails(@Param("prize_log_id") String prizeLogId, PageBounds order); List<JSONObject> listDetails(@Param("prize_log_id") String prizeLogId, PageBounds order);
void clearDetailsOfReport(@Param("record_id") String recordId); void clearDetailsOfReport(@Param("record_id") String recordId);
List<JSONObject> findCommissionDetailById(@Param("record_id")String record_id, @Param("manager_id")String managerId);
} }

@ -30,4 +30,6 @@ public interface FinancialBDPrizeRecordMapper {
@AutoSql(type = SqlType.DELETE) @AutoSql(type = SqlType.DELETE)
void delete(@Param("record_id") String recordId); void delete(@Param("record_id") String recordId);
List<JSONObject> getReportByManagerId(@Param("manager_id") String managerId);
} }

@ -15,4 +15,26 @@
INNER JOIN sys_clients c ON c.client_id = d.client_id INNER JOIN sys_clients c ON c.client_id = d.client_id
WHERE d.prize_log_id = #{prize_log_id} WHERE d.prize_log_id = #{prize_log_id}
</select> </select>
<select id="findCommissionDetailById" resultType="com.alibaba.fastjson.JSONObject">
SELECT
c.client_moniker,
c.source,
d.order_date_from,
d.order_date_to,
d.rate_value,
d.client_create_months,
d.bd_rate,
d.total_transaction,
d.prize_value,
d.coefficient,
d.channel
FROM
financial_bd_prize_detail d
INNER JOIN financial_bd_prize_log l ON d.prize_log_id = l.prize_log_id
INNER JOIN sys_clients c ON c.client_id = d.client_id
WHERE
d.manager_id = #{manager_id}
AND l.record_id = #{record_id}
ORDER BY client_moniker asc,order_date_from asc
</select>
</mapper> </mapper>

@ -34,5 +34,22 @@
WHERE fbpr.record_id = fbpl.record_id WHERE fbpr.record_id = fbpl.record_id
AND fbpr.month = #{month} AND fbpr.month = #{month}
</select> </select>
<select id="getReportByManagerId" resultType="com.alibaba.fastjson.JSONObject">
SELECT
r.*,bd_level,
bd_name,
l.kpi_amount,
l.prize_type,
l.manager_id,
sum(total_prize) total_prize,
sum(send_prize) total_send_prize,
sum(total_donation) total_donation,
sum(hold_prize) total_hold_prize,
sum(l.total_amount) total_amount
FROM financial_bd_prize_records r
INNER JOIN financial_bd_prize_log l ON l.record_id = r.record_id
WHERE l.manager_id = #{manager_id}
GROUP BY r.record_id
ORDER BY `month` DESC
</select>
</mapper> </mapper>

@ -144,7 +144,17 @@ define(['angular', '../../analysis/bd/analysis-bd'], function (angular) {
}; };
$scope.exportCommission = function (monModal) { $scope.exportCommission = function (monModal) {
location.href = '/sys/bd_prize/commission/export/' + monModal; location.href = '/sys/bd_prize/commission/export/' + monModal;
} };
$scope.loadPersonalCommission = function () {
if (($scope.currentUser.role & parseInt('100', 2)) > 0 && $scope.currentUser.org_id === 1) {
$http.get('/sys/bd_prize/commission/personal/bd_user').then(function (resp) {
$scope.personalCommission = resp.data;
})
}
};
$scope.loadPersonalCommission();
}]); }]);
app.controller('bdRateConfigCtrl', ['$scope', '$http', 'rates', function ($scope, $http, rates) { app.controller('bdRateConfigCtrl', ['$scope', '$http', 'rates', function ($scope, $http, rates) {
$scope.bdLevels = [{value: 1, label: 'Junior'}, {value: 2, label: 'Intermediate'}, {value: 3, label: 'Senior'}]; $scope.bdLevels = [{value: 1, label: 'Junior'}, {value: 2, label: 'Intermediate'}, {value: 3, label: 'Senior'}];

@ -158,6 +158,9 @@
<a ui-sref=".detail({bdId:log.manager_id})" ng-if="log.prize_type==0"> <a ui-sref=".detail({bdId:log.manager_id})" ng-if="log.prize_type==0">
<i class="fa fa-search"></i> <i class="fa fa-search"></i>
</a> </a>
<a ng-href="/sys/bd_prize/commission/export/{{report.month}}/bd_users/{{log.manager_id}}" ng-if="log.prize_type==0">
<i class="fa fa-download"></i>
</a>
</td> </td>
</tr> </tr>
</tbody> </tbody>

@ -68,6 +68,52 @@
</div> </div>
</div> </div>
</div> </div>
<div class="box box-info" ng-if="('100'|withRole)">
<div class="box-header">个人提成</div>
<div class="box-body">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Month</th>
<th>KPI</th>
<th>BD Level</th>
<th>Transaction Amount</th>
<th>Total Commission</th>
<th>Send Commission</th>
<th>Hold Commission</th>
<th>Prize Type</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="commission in personalCommission">
<td>{{commission.month}}</td>
<td>
<span ng-if="commission.kpi_amount">{{commission.kpi_amount}}</span>
<span ng-if="!commission.kpi_amount">0.00</span>
</td>
<td ng-bind="commission.bd_level|financialBdLevel"></td>
<td>{{commission.total_amount|currency:'AUD '}}</td>
<td ng-bind="commission.total_prize|currency:'AUD '"></td>
<td ng-bind="commission.total_send_prize|currency:'AUD '"></td>
<td ng-bind="commission.total_hold_prize|currency:'AUD '"></td>
<td>
<span ng-if="commission.prize_type==0">BD</span>
<span ng-if="commission.prize_type==1">Group</span>
</td>
<td>
<a ui-sref=".bd_detail({month:commission.month})" ng-if="commission.prize_type==0">
<i class="fa fa-search"></i>
</a>
<a ng-href="/sys/bd_prize/commission/export/{{commission.month}}/bd_users" ng-if="commission.prize_type==0">
<i class="fa fa-download"></i>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="box box-info"> <div class="box box-info">
<div class="box-header">提成规则</div> <div class="box-header">提成规则</div>
<div class="box-body"> <div class="box-body">

Loading…
Cancel
Save