diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java index dbb3655e..d50a5c89 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementInfoController.java @@ -1,5 +1,8 @@ package com.bonus.material.settlement.controller; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.OutputStream; import java.math.BigDecimal; import java.math.RoundingMode; @@ -37,6 +40,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.formula.functions.T; @@ -55,6 +59,8 @@ import com.bonus.common.core.utils.poi.ExcelUtil; import com.bonus.common.core.web.page.TableDataInfo; import java.util.ArrayList; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; /** * 结算信息Controller @@ -1541,6 +1547,7 @@ public class SltAgreementInfoController extends BaseController { if (vo != null && !ObjectUtil.isEmpty(vo)) { vo.setAgreementId(info.getAgreementId()); vo.setAgreementCode(info.getAgreementCode()); + vo.setSettlementType(settlementType); dataList.add(vo); } } catch (Exception e) { @@ -1656,4 +1663,214 @@ public class SltAgreementInfoController extends BaseController { log.error("导出区间费用汇总失败", e); } } + + + /** + * 一键批量导出未结算报表(zip) + */ + @ApiOperation(value = "一键批量导出未结算报表") + @PreventRepeatSubmit + @SysLog(title = "结算信息", businessType = OperaType.EXPORT, logType = 1,module = "结算管理->一键批量导出未结算报表") + @PostMapping("/exportUnsettled") + public void exportUnsettled(HttpServletResponse response, @RequestBody List list) throws Exception { + // 创建临时文件夹 + String tempDir = System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID(); + new File(tempDir).mkdirs(); + + try { + for(SltAgreementInfo info : list){ + if(info.getAgreementId() == null){ + continue; + } + //根据协议id获取结算单位和结算工程 + SltAgreementInfo agreementInfo = sltAgreementInfoMapper.getUnitAndProjectByAgreementId(info.getAgreementId()); + // 生成文件名 + String fileName = ""; + String unitName = ""; + String projectName = ""; + unitName = agreementInfo.getUnitName(); + projectName = agreementInfo.getProjectName(); + + //租赁费用明细 + BigDecimal totalCostLease = BigDecimal.valueOf(0.00); + List leaseList = new ArrayList<>(); + leaseList = sltAgreementInfoMapper.getLeaseList(info); + + for (SltAgreementInfo bean : leaseList) { + if (null == bean.getLeasePrice()) { + bean.setLeasePrice(BigDecimal.valueOf(0.00)); + } + if (null == bean.getNum()) { + bean.setNum(BigDecimal.valueOf(0L)); + } + if (null == bean.getLeaseDays()) { + bean.setLeaseDay(0L); + } + BigDecimal leasePrice = bean.getLeasePrice(); + BigDecimal num = bean.getNum(); + BigDecimal leaseDays = new BigDecimal(bean.getLeaseDays()); + BigDecimal costs = leasePrice.multiply(num).multiply(leaseDays); + if(costs!=null){ + totalCostLease = totalCostLease.add(costs); + } + bean.setCosts(costs); + } + List lease = Convert.toList(SltLeaseInfo.class, leaseList); + + //丢失费用明细 + BigDecimal totalCostLose = BigDecimal.valueOf(0.00); + List loseList = new ArrayList<>(); + + loseList = sltAgreementInfoMapper.getLoseList(info); + + for (SltAgreementInfo bean : loseList) { + if (null == bean.getBuyPrice()) { + bean.setBuyPrice(BigDecimal.valueOf(0.00)); + } + if (null == bean.getNum()) { + bean.setNum(BigDecimal.valueOf(0L)); + } + BigDecimal buyPrice = bean.getBuyPrice(); + BigDecimal num = bean.getNum(); + // 原价 x 数量 + BigDecimal costs = buyPrice.multiply(num); + if(costs!=null){ + totalCostLose = totalCostLose.add(costs); + } + //计算租赁费用 + bean.setCosts(costs); + } + List lose = Convert.toList(SltLeaseInfo.class, loseList); + + //维修费用明细 + BigDecimal totalCostRepair = BigDecimal.valueOf(0.00); + List repairList = new ArrayList<>(); + + + List taskRepairList = taskMapper.getTaskIdList(info); + if (null != taskRepairList && !taskRepairList.isEmpty()) { + repairList = sltAgreementInfoMapper.getRepairDetailsList(info, taskRepairList); + } + + for (SltAgreementInfo bean : repairList) { + if (bean.getCosts()!=null && (bean.getPartType().equals("收费"))) { + totalCostRepair = totalCostRepair.add(bean.getCosts()); + } + } + List repair = Convert.toList(SltLeaseInfo.class, repairList); + + //报废费用明细 + BigDecimal totalCostScrap = BigDecimal.valueOf(0.00); + List scrapList = new ArrayList<>(); + + List taskScrapList = taskMapper.getTaskIdList(info); + if (null != taskScrapList && !taskScrapList.isEmpty()) { + scrapList = sltAgreementInfoMapper.getScrapDetailsList(info, taskScrapList); + } + + + for (SltAgreementInfo bean : scrapList) { + if (bean.getCosts()!=null && (bean.getPartType().equals("收费"))) { + totalCostScrap = totalCostScrap.add(bean.getCosts()); + } + } + List scrap = Convert.toList(SltLeaseInfo.class, scrapList); + + //减免费用明细 + BigDecimal totalCostReduction = BigDecimal.valueOf(0.00); + List reductionList = new ArrayList<>(); + + if (info.getAgreementId() != null){ + SltAgreementReduce bean =new SltAgreementReduce(); + bean.setAgreementId(info.getAgreementId()); + reductionList = sltAgreementRecudceMapper.getReductionList(bean); + } + + for (SltAgreementReduce reduction : reductionList) { + if(reduction.getLeaseMoney()!=null){ + totalCostReduction = totalCostReduction.add(reduction.getLeaseMoney()); + } + } + List reduction = Convert.toList(SltLeaseInfo.class, reductionList); + + + List> resultsLease = new ArrayList<>(); + List> resultsLose = new ArrayList<>(); + List> resultsRepair = new ArrayList<>(); + List> resultsScrap = new ArrayList<>(); + List> resultsReduction = new ArrayList<>(); + if (lease!= null) { + for (SltLeaseInfo bean : lease) { + Map maps = outReceiveDetailsBeanToMap(bean, 1, 1); + resultsLease.add(maps); + } + } + if (lose!= null) { + for (SltLeaseInfo bean : lose) { + Map maps = outReceiveDetailsBeanToMap(bean, 2, 1); + resultsLose.add(maps); + } + } + if (repair!= null) { + for (SltLeaseInfo bean : repair) { + Map maps = outReceiveDetailsBeanToMap(bean, 3, 1); + resultsRepair.add(maps); + } + } + if (scrap!= null) { + for (SltLeaseInfo bean : scrap) { + Map maps = outReceiveDetailsBeanToMap(bean, 4, 1); + resultsScrap.add(maps); + } + } + if (reduction!= null) { + for (SltLeaseInfo bean : reduction) { + Map maps = outReceiveDetailsBeanToMap(bean, 5, 1); + resultsReduction.add(maps); + } + } + + List headersLease = receiveDetailsHeader(1,1); + List headersLose = receiveDetailsHeader(2,1); + List headersRepair = receiveDetailsHeader(3,1); + List headersScrap = receiveDetailsHeader(4,1); + List headersReduction = receiveDetailsHeader(5,1); + + fileName = agreementInfo.getAgreementCode() + "-" + unitName + "-" + projectName ; + // 导出单个Excel文件 + String filePath = tempDir + File.separator + fileName; + try (FileOutputStream fos = new FileOutputStream(filePath)) { + HSSFWorkbook workbook = PoiOutPage.excelForcheckAll(resultsLease,resultsLose,resultsRepair,resultsScrap,resultsReduction, headersLease,headersLose,headersRepair,headersScrap,headersReduction, "结算明细",projectName,unitName,totalCostLease,totalCostLose,totalCostRepair,totalCostScrap,totalCostReduction); + 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(); + } + } + } + } catch (Exception e) { + log.error("一键批量导出未结算报表失败", e); + } finally { + // 删除临时文件 + FileUtils.deleteDirectory(new File(tempDir)); + } + } } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java index 4636540e..acf26451 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java @@ -310,4 +310,6 @@ public interface SltAgreementInfoMapper { * @param bean 协议ID */ List getRepairCodeList(SltAgreementInfo bean); + + SltAgreementInfo getUnitAndProjectByAgreementId(Long agreementId); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementInfoService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementInfoService.java index d00384a2..8f697acb 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementInfoService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementInfoService.java @@ -171,4 +171,5 @@ public interface ISltAgreementInfoService { List getRepairCodeList(SltAgreementInfo bean); + } diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialMachineMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialMachineMapper.xml index f6edbce2..559748f7 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialMachineMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialMachineMapper.xml @@ -1347,7 +1347,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND sai.back_id IS NULL AND bp.external_id IS NOT NULL AND bu.type_id = 36 - and sd.dept_id not in (342,345,347,348,101) + and sd.dept_id not in (342,345,347,348,101,344) and bp.pro_id not in (3414,1192,3321,3595) and bp.pro_center IS NOT NULL @@ -1421,7 +1421,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sai.`status` = '0' AND sai.end_time IS NULL AND sai.back_id IS NULL - and sd.dept_id not in (342,345,347,348,101) + and sd.dept_id not in (342,345,347,348,101,344) and bp.pro_id not in (3414,1192,3321,3595) AND sd.dept_name like concat('%',#{impUnitName},'%') @@ -1516,7 +1516,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND sai.back_id IS NULL AND bu.unit_name is not null AND bp.external_id is not NULL - and sd.dept_id not in (342,345,347,348,101) + and sd.dept_id not in (342,345,347,348,101,344) and bp.pro_id not in (3414,1192,3321,3595) and bp.pro_center IS NOT NULL @@ -1605,7 +1605,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit WHERE sd.dept_name IS NOT NULL - and sd.dept_id not in (342,345,347,348,101) + and sd.dept_id not in (342,345,347,348,101,344) AND sd.dept_name LIKE CONCAT('%', #{impUnitName}, '%') @@ -1766,7 +1766,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND sai.back_id IS NULL AND bu.unit_name is not null AND bp.external_id is not NULL - and sd.dept_id not in (342,345,347,348,101) + and sd.dept_id not in (342,345,347,348,101,344) and bp.pro_id not in (3414,1192,3321,3595) AND sd.dept_name = #{impUnitName} diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml index 0b551412..54aebdec 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml @@ -1195,6 +1195,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" FROM bm_agreement_info bai INNER JOIN slt_agreement_info sai ON bai.agreement_id = sai.agreement_id WHERE sai.is_slt = 0 + and bai.is_show != 0 ) diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseTaskMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseTaskMapper.xml index d4b53669..682c5049 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseTaskMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseTaskMapper.xml @@ -593,6 +593,7 @@ LEFT JOIN sys_workflow_config swc ON swn.id = swc.node_id LEFT JOIN sys_workflow_record_history swrs ON swr.id = swrs.record_id where 1=1 + and swr.task_type = 19 and bp.imp_unit = #{deptId} and lai.code = #{code} and lai.task_id = #{taskId} diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml index 67639cd7..adbe2ad0 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml @@ -1456,4 +1456,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where sai.agreement_id = #{agreementId} AND mt.jiju_type = #{settlementType} + +