批量导出月结明细表
This commit is contained in:
parent
529f56c84f
commit
e977fc087c
|
|
@ -22,6 +22,7 @@ import com.bonus.sgzb.material.config.PoiOutPage;
|
||||||
import com.bonus.sgzb.material.domain.*;
|
import com.bonus.sgzb.material.domain.*;
|
||||||
import com.bonus.sgzb.material.service.SltAgreementInfoService;
|
import com.bonus.sgzb.material.service.SltAgreementInfoService;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -30,13 +31,15 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import static com.bonus.sgzb.common.core.web.page.TableSupport.PAGE_NUM;
|
import static com.bonus.sgzb.common.core.web.page.TableSupport.PAGE_NUM;
|
||||||
import static com.bonus.sgzb.common.core.web.page.TableSupport.PAGE_SIZE;
|
import static com.bonus.sgzb.common.core.web.page.TableSupport.PAGE_SIZE;
|
||||||
|
|
@ -179,6 +182,167 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
util.exportExcel(response, leaseInfoList, "租赁明细导出");
|
util.exportExcel(response, leaseInfoList, "租赁明细导出");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租赁明细导出
|
||||||
|
*/
|
||||||
|
@Log(title = "租赁明细导出", businessType = BusinessType.EXPORT)
|
||||||
|
@PostMapping("/exportLeaseAll")
|
||||||
|
// @RequiresPermissions("ndertake:export_1")
|
||||||
|
public void exportLeaseAll(HttpServletResponse response, @RequestBody List<AgreementInfo> list) throws Exception {
|
||||||
|
// 创建临时文件夹
|
||||||
|
String tempDir = System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID();
|
||||||
|
new File(tempDir).mkdirs();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 遍历每个协议信息
|
||||||
|
for (AgreementInfo info : list) {
|
||||||
|
// 生成文件名
|
||||||
|
String fileName = "";
|
||||||
|
String fileNameThree = "";
|
||||||
|
List<SltAgreementInfo> explist = new ArrayList<>();
|
||||||
|
List<SltAgreementInfo> explistThree = new ArrayList<>();
|
||||||
|
List<LeaseInfo> leaseInfoList = new ArrayList<>();
|
||||||
|
List<LeaseInfo> leaseInfoListThree = new ArrayList<>();
|
||||||
|
if(Objects.equals(info.getCostBearingParty(), "01")){
|
||||||
|
// 获取导出数据
|
||||||
|
explist = sltAgreementInfoService.getLeaseListOne(Collections.singletonList(info));
|
||||||
|
leaseInfoList = Convert.toList(LeaseInfo.class, explist);
|
||||||
|
}else if(Objects.equals(info.getCostBearingParty(), "03")){
|
||||||
|
// 获取导出数据
|
||||||
|
explistThree = sltAgreementInfoService.getLeaseListThree(Collections.singletonList(info));
|
||||||
|
leaseInfoListThree = Convert.toList(LeaseInfo.class, explistThree);
|
||||||
|
}else{
|
||||||
|
// 获取导出数据
|
||||||
|
explist = sltAgreementInfoService.getLeaseListOne(Collections.singletonList(info));
|
||||||
|
explistThree = sltAgreementInfoService.getLeaseListThree(Collections.singletonList(info));
|
||||||
|
leaseInfoList = Convert.toList(LeaseInfo.class, explist);
|
||||||
|
leaseInfoListThree = Convert.toList(LeaseInfo.class, explistThree);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Objects.equals(info.getCostBearingParty(), "01")){
|
||||||
|
// 计算总成本
|
||||||
|
BigDecimal totalCost = BigDecimal.valueOf(0.00);
|
||||||
|
for (SltAgreementInfo sltAgreementInfo : explist) {
|
||||||
|
totalCost = totalCost.add(sltAgreementInfo.getRealCosts());
|
||||||
|
}
|
||||||
|
fileName ="费用承担方01_"+ info.getAgreementCode() + "_" + info.getUnitName() + "_" + info.getProjectName() + "_设备租赁结算单.xls";
|
||||||
|
// 导出单个Excel文件
|
||||||
|
String filePath = tempDir + File.separator + fileName;
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
||||||
|
HSSFWorkbook workbook = PoiOutPage.excelForcheckTwo(
|
||||||
|
leaseInfoList.stream()
|
||||||
|
.map(bean -> outReceiveDetailsBeanToMap(bean, 1, 0))
|
||||||
|
.collect(Collectors.toList()),
|
||||||
|
receiveDetailsHeader(1, 0),
|
||||||
|
"重庆市送变电工程有限公司设备租赁结算单",
|
||||||
|
info.getProjectName(),
|
||||||
|
info.getUnitName(),
|
||||||
|
totalCost,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
workbook.write(fos);
|
||||||
|
}
|
||||||
|
}else if(Objects.equals(info.getCostBearingParty(), "03")){
|
||||||
|
// 计算总成本
|
||||||
|
BigDecimal totalCost = BigDecimal.valueOf(0.00);
|
||||||
|
for (SltAgreementInfo sltAgreementInfo : explistThree) {
|
||||||
|
totalCost = totalCost.add(sltAgreementInfo.getRealCosts());
|
||||||
|
}
|
||||||
|
|
||||||
|
fileNameThree ="费用承担方03_"+ info.getAgreementCode() + "_" + info.getUnitName() + "_" + info.getProjectName() + "_设备租赁结算单.xls";
|
||||||
|
// 导出单个Excel文件
|
||||||
|
String filePath = tempDir + File.separator + fileNameThree;
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
||||||
|
HSSFWorkbook workbook = PoiOutPage.excelForcheckTwo(
|
||||||
|
leaseInfoListThree.stream()
|
||||||
|
.map(bean -> outReceiveDetailsBeanToMap(bean, 3, 0))
|
||||||
|
.collect(Collectors.toList()),
|
||||||
|
receiveDetailsHeader(3, 0),
|
||||||
|
"重庆市送变电工程有限公司设备租赁结算单",
|
||||||
|
info.getProjectName(),
|
||||||
|
info.getUnitName(),
|
||||||
|
totalCost,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
workbook.write(fos);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// 计算总成本
|
||||||
|
BigDecimal totalCost = BigDecimal.valueOf(0.00);
|
||||||
|
for (SltAgreementInfo sltAgreementInfo : explist) {
|
||||||
|
totalCost = totalCost.add(sltAgreementInfo.getRealCosts());
|
||||||
|
}
|
||||||
|
|
||||||
|
fileName ="费用承担方01_"+ info.getAgreementCode() + "_" + info.getUnitName() + "_" + info.getProjectName() + "_设备租赁结算单.xls";
|
||||||
|
// 导出单个Excel文件
|
||||||
|
String filePath = tempDir + File.separator + fileName;
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
||||||
|
HSSFWorkbook workbook = PoiOutPage.excelForcheckTwo(
|
||||||
|
leaseInfoList.stream()
|
||||||
|
.map(bean -> outReceiveDetailsBeanToMap(bean, 1, 0))
|
||||||
|
.collect(Collectors.toList()),
|
||||||
|
receiveDetailsHeader(1, 0),
|
||||||
|
"重庆市送变电工程有限公司设备租赁结算单",
|
||||||
|
info.getProjectName(),
|
||||||
|
info.getUnitName(),
|
||||||
|
totalCost,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
workbook.write(fos);
|
||||||
|
}
|
||||||
|
// 计算总成本
|
||||||
|
BigDecimal totalCostThree = BigDecimal.valueOf(0.00);
|
||||||
|
for (SltAgreementInfo sltAgreementInfo : explistThree) {
|
||||||
|
totalCost = totalCost.add(sltAgreementInfo.getRealCosts());
|
||||||
|
}
|
||||||
|
|
||||||
|
fileNameThree ="费用承担方03_"+ info.getAgreementCode() + "_" + info.getUnitName() + "_" + info.getProjectName() + "_设备租赁结算单.xls";
|
||||||
|
// 导出单个Excel文件
|
||||||
|
String filePathThree = tempDir + File.separator + fileNameThree;
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(filePathThree)) {
|
||||||
|
HSSFWorkbook workbook = PoiOutPage.excelForcheckTwo(
|
||||||
|
leaseInfoListThree.stream()
|
||||||
|
.map(bean -> outReceiveDetailsBeanToMap(bean, 3, 0))
|
||||||
|
.collect(Collectors.toList()),
|
||||||
|
receiveDetailsHeader(3, 0),
|
||||||
|
"重庆市送变电工程有限公司设备租赁结算单",
|
||||||
|
info.getProjectName(),
|
||||||
|
info.getUnitName(),
|
||||||
|
totalCostThree,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
workbook.write(fos);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 创建压缩包
|
||||||
|
String zipFileName = "设备租赁结算单_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".zip";
|
||||||
|
response.setContentType("application/zip");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(zipFileName, "UTF-8"));
|
||||||
|
|
||||||
|
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
|
||||||
|
File[] files = new File(tempDir).listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
zipOut.putNextEntry(new ZipEntry(file.getName()));
|
||||||
|
try (FileInputStream fis = new FileInputStream(file)) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = fis.read(buffer)) > 0) {
|
||||||
|
zipOut.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zipOut.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// 删除临时文件夹
|
||||||
|
FileUtils.deleteDirectory(new File(tempDir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 去重单位和工程名称
|
* 去重单位和工程名称
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue