From 6041f97e02db11b1ee319f9074ab4d717e0f718e Mon Sep 17 00:00:00 2001 From: yangkai Date: Sat, 2 Mar 2019 14:43:41 +0800 Subject: [PATCH] =?UTF-8?q?bd=E5=8F=AF=E4=BB=A5=E6=9F=A5=E7=9C=8B=E3=80=81?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=87=AA=E5=B7=B1=E7=9A=84=E6=8F=90=E6=88=90?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/bdprize/core/BDPrizeService.java | 4 + .../core/impls/BDPrizeServiceImpl.java | 77 +++++++++++++++++++ .../manage/bdprize/web/BDPrizeController.java | 15 ++++ .../FinancialBDPrizeDetailMapper.java | 2 + .../FinancialBDPrizeRecordMapper.java | 2 + .../FinancialBDPrizeDetailMapper.xml | 22 ++++++ .../FinancialBDPrizeRecordMapper.xml | 19 ++++- src/main/ui/static/config/bdprize/bdprize.js | 12 ++- .../templates/bd_prize_month_report.html | 3 + .../bdprize/templates/bd_prize_root.html | 46 +++++++++++ 10 files changed, 200 insertions(+), 2 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/BDPrizeService.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/BDPrizeService.java index 5ee09d9b7..55fa181a1 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/BDPrizeService.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/BDPrizeService.java @@ -44,4 +44,8 @@ public interface BDPrizeService { void updateBdKpiConfig(List configs, JSONObject manager)throws ParseException; void exportCommissionMonth(String month, HttpServletResponse response) throws Exception; + + void exportCommissionDetail(String month, String managerId, HttpServletResponse response); + + List findCommissionList(JSONObject manager); } diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java index 741b3b17c..a0929b943 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/core/impls/BDPrizeServiceImpl.java @@ -20,6 +20,7 @@ import com.alibaba.fastjson.JSONObject; import com.github.miemiedev.mybatis.paginator.domain.Order; 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.DateUtils; 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.util.HSSFColor; import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +36,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; import java.io.OutputStream; import java.math.BigDecimal; 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 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 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) { switch (level) { case 0: @@ -639,4 +702,18 @@ public class BDPrizeServiceImpl implements BDPrizeService { return "Unknown"; } } + + private String financialClientSource(int source) { + switch (source) { + case 1: + return "BD"; + case 2: + return "Apply"; + case 3: + return "Distribute"; + default: + return "Unknown"; + } + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/bdprize/web/BDPrizeController.java b/src/main/java/au/com/royalpay/payment/manage/bdprize/web/BDPrizeController.java index d817e993e..58d8b47ab 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bdprize/web/BDPrizeController.java +++ b/src/main/java/au/com/royalpay/payment/manage/bdprize/web/BDPrizeController.java @@ -104,4 +104,19 @@ public class BDPrizeController { public void exportCommissionMonth(@PathVariable String month, HttpServletResponse response) throws Exception { 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 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); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.java index ea14473a1..13b0d7868 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.java @@ -21,4 +21,6 @@ public interface FinancialBDPrizeDetailMapper { List listDetails(@Param("prize_log_id") String prizeLogId, PageBounds order); void clearDetailsOfReport(@Param("record_id") String recordId); + + List findCommissionDetailById(@Param("record_id")String record_id, @Param("manager_id")String managerId); } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.java index 78c5aace1..91ef5d252 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.java @@ -30,4 +30,6 @@ public interface FinancialBDPrizeRecordMapper { @AutoSql(type = SqlType.DELETE) void delete(@Param("record_id") String recordId); + + List getReportByManagerId(@Param("manager_id") String managerId); } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.xml index 193b85b93..d893e867e 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeDetailMapper.xml @@ -15,4 +15,26 @@ INNER JOIN sys_clients c ON c.client_id = d.client_id WHERE d.prize_log_id = #{prize_log_id} + \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.xml index a62886d13..952fd63af 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/financial/FinancialBDPrizeRecordMapper.xml @@ -34,5 +34,22 @@ WHERE fbpr.record_id = fbpl.record_id AND fbpr.month = #{month} - + \ No newline at end of file diff --git a/src/main/ui/static/config/bdprize/bdprize.js b/src/main/ui/static/config/bdprize/bdprize.js index b5d76ee4e..0b84b33d3 100644 --- a/src/main/ui/static/config/bdprize/bdprize.js +++ b/src/main/ui/static/config/bdprize/bdprize.js @@ -144,7 +144,17 @@ define(['angular', '../../analysis/bd/analysis-bd'], function (angular) { }; $scope.exportCommission = function (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) { $scope.bdLevels = [{value: 1, label: 'Junior'}, {value: 2, label: 'Intermediate'}, {value: 3, label: 'Senior'}]; diff --git a/src/main/ui/static/config/bdprize/templates/bd_prize_month_report.html b/src/main/ui/static/config/bdprize/templates/bd_prize_month_report.html index 29a0a976c..1093b05de 100644 --- a/src/main/ui/static/config/bdprize/templates/bd_prize_month_report.html +++ b/src/main/ui/static/config/bdprize/templates/bd_prize_month_report.html @@ -158,6 +158,9 @@ + + + diff --git a/src/main/ui/static/config/bdprize/templates/bd_prize_root.html b/src/main/ui/static/config/bdprize/templates/bd_prize_root.html index c7e5c591d..9603ee070 100644 --- a/src/main/ui/static/config/bdprize/templates/bd_prize_root.html +++ b/src/main/ui/static/config/bdprize/templates/bd_prize_root.html @@ -68,6 +68,52 @@ +
+
个人提成
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
MonthKPIBD LevelTransaction AmountTotal CommissionSend CommissionHold CommissionPrize TypeDetails
{{commission.month}} + {{commission.kpi_amount}} + 0.00 + {{commission.total_amount|currency:'AUD '}} + BD + Group + + + + + + + +
+
+
提成规则