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