使用固定模板导出

/**
* 模板导出
* @param request
* @param response
* @param redirectAttributes
* @param reportId
* @return
*/
public String importFileTemplate(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes,String reportId ) {
try {
File dizhi = new File(this.getClass().getResource("/").getPath());
String path = dizhi.toString() +"/template/fundProjectTemplate.xlsx";
FileInputStream tps = new FileInputStream(new File(path));
final XSSFWorkbook tpWorkbook = new XSSFWorkbook(tps);
// 新建一个Excel的工作空间
XSSFWorkbook workbook = new XSSFWorkbook();
// 把模板复制到新建的Excel
workbook = tpWorkbook;
// 第一个sheet页
Sheet sheet1 = workbook.getSheetAt(0);
// 第二个sheet页
Sheet sheet2 = workbook.getSheetAt(1);
// 时间格式化
SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd");
// 金额格式化使用
BigDecimal wan = new BigDecimal(10000);

SubFund subFund =new SubFund();
subFund.setReportId(reportId);
List<SubFund> list = this.findList(subFund);
if (list.size()>0){
for (int i = 0; i < list.size(); i++) {
SubFund fund = list.get(i);
// 第一个行
Row row = (Row) sheet1.createRow(i+1);
// 基金名称
Cell cell = row.createCell(0);
String value = "";
CompanyBase company = fund.getCompany();
if (company!=null){
Map<String,Object> dataMap = companyBaseService.getCompanyByNameTyc(company);
CompanyBase companyNew = (CompanyBase) dataMap.get("company");
if (companyNew!=null){
company = companyNew;
value=companyNew.getCompanyName();
}
}
cell.setCellValue(value);
// 基金管理人名称
cell = row.createCell(1);
cell.setCellValue(fund.getFundManager());
// 基金注册成立日
cell = row.createCell(2);
if (fund.getFoundationDate()!=null){
String foundationDate = format.format(fund.getFoundationDate());
cell.setCellValue(foundationDate);
}else {
cell.setCellValue("");
}
// 首次出资时间
cell = row.createCell(3);
if (fund.getInitialContribution()!=null){
String initialContribution = format.format(fund.getInitialContribution());
cell.setCellValue(initialContribution);
}else {
cell.setCellValue("");
}
// 基金规模(万元)
cell = row.createCell(4);
if (fund.getFunSize()!=null){
cell.setCellValue(fund.getFunSize().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell.setCellValue("");
}

// 基金认缴金额(万元)
cell = row.createCell(5);
if (fund.getSubscribedAmount()!=null){
cell.setCellValue(fund.getSubscribedAmount().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell.setCellValue("");
}
// 认缴比例(%)
cell = row.createCell(6);
cell.setCellValue(fund.getSubscriptionProportion()==null?"":fund.getSubscriptionProportion().toString());
// 基金实缴金额(万元)
cell = row.createCell(7);
if (fund.getPaidAmount()!=null){
cell.setCellValue(fund.getPaidAmount().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell.setCellValue("");
}
// 出资进度(%)
cell = row.createCell(8);
cell.setCellValue(fund.getProgressContribution()==null?"":fund.getProgressContribution().toString());
// 基金期限(年)
cell = row.createCell(9);
if (StringUtils.isNotBlank(fund.getFundTerm())){
cell.setCellValue(fund.getFundTerm());
}else {
cell.setCellValue("");
}
// 基金阶段
cell = row.createCell(10);
if (StringUtils.isNotBlank(fund.getFundStage())){
cell.setCellValue(DictUtils.getDictLabel(fund.getFundStage(),"fund_phase",""));
}else {
cell.setCellValue("");
}
// 投资回款(万元)
cell = row.createCell(11);
if (fund.getReturnInvestment()!=null){
cell.setCellValue(fund.getReturnInvestment().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell.setCellValue("");
}
// 已回收成本(万元)
cell = row.createCell(12);
if (fund.getCostRecovered()!=null){
cell.setCellValue(fund.getCostRecovered().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell.setCellValue("");
}
// 最新估值(万元)
cell = row.createCell(13);
if (fund.getLatestValuation()!=null){
cell.setCellValue(fund.getLatestValuation().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell.setCellValue("");
}
// 基金DPI
cell = row.createCell(14);
cell.setCellValue(fund.getFundDpi()==null?"":fund.getFundDpi().toString());

// 基金IRR
cell = row.createCell(15);
cell.setCellValue(fund.getFundIrr()==null?"":fund.getFundIrr().toString());

// 回报倍数
cell = row.createCell(16);
cell.setCellValue(fund.getMultipleReturn()==null?"":fund.getMultipleReturn().toString());


BfInvestGroup bfInvestGroupNew = new BfInvestGroup();
bfInvestGroupNew.setReportId(reportId);
bfInvestGroupNew.setFundId(fund.getId());
List<BfInvestGroup> allList = bfInvestGroupService.findAllList(bfInvestGroupNew);
if (allList.size()>0){
for (int j = 0; j < allList.size(); j++) {
BfInvestGroup bfInvestGroup = allList.get(j);
Row row2 = (Row) sheet2.createRow(j+1);
// 基金名称
Cell cell2 = row2.createCell(0);
String value2 = "";
CompanyBase company2 = fund.getCompany();
if (company2!=null){
Map<String,Object> dataMap = companyBaseService.getCompanyByNameTyc(company);
CompanyBase companyNew = (CompanyBase) dataMap.get("company");
if (companyNew!=null){
company2 = companyNew;
value2=companyNew.getCompanyName();
}
}
cell2.setCellValue(value2);
// 项目名称
cell2 = row2.createCell(1);
if (bfInvestGroup.getCompany()!=null){
cell2.setCellValue(bfInvestGroup.getCompany().getCompanyName());
}else {
cell2.setCellValue("");
}
// 投资时间
cell2 = row2.createCell(2);
if (bfInvestGroup.getInvestmentTime()!=null){
String investmentTime = format.format(bfInvestGroup.getInvestmentTime());
cell2.setCellValue(investmentTime);
}else {
cell2.setCellValue("");
}
// 投资时估值(万元)
cell2 = row2.createCell(3);
if (bfInvestGroup.getPreInvestmentVal()!=null){
cell2.setCellValue(bfInvestGroup.getPreInvestmentVal().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell2.setCellValue("");
}
// 划款金额(万元)
cell2 = row2.createCell(4);
if (bfInvestGroup.getTransferAmount()!=null){
cell2.setCellValue(bfInvestGroup.getTransferAmount().divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell2.setCellValue("");
}
// 最新持股比例(%)
cell2 = row2.createCell(5);
cell2.setCellValue(bfInvestGroup.getLatestShareholdingRatio()==null?"":bfInvestGroup.getLatestShareholdingRatio().toString());
// 项目最新估值(万元)
cell2 = row2.createCell(6);
if (bfInvestGroup.getLatestValuation()!=null){
cell2.setCellValue(new BigDecimal(bfInvestGroup.getLatestValuation()).divide(wan,6, RoundingMode.HALF_UP).toString());
}else {
cell2.setCellValue("");
}
}
}
}
}
response.setContentType("application/vnd.ms-excel");
response.addHeader("Content-Disposition", "attachment;filename="
+ java.net.URLEncoder.encode("基金项目模板", "UTF-8")
+ ".xlsx");
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();

return null;
} catch (Exception e) {
e.printStackTrace();
AjaxResult.error("导入模板下载失败!");
}
return "";
}
posted @ 2022-11-03 17:24  翘中之楚  阅读(24)  评论(0编辑  收藏  举报