diff --git a/ruoyi-admin/src/main/java/com/ruoyi/financial/controller/FinancialReceivablesController.java b/ruoyi-admin/src/main/java/com/ruoyi/financial/controller/FinancialReceivablesController.java index b661a651..92982a3a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/financial/controller/FinancialReceivablesController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/financial/controller/FinancialReceivablesController.java @@ -2,6 +2,8 @@ package com.ruoyi.financial.controller; import java.io.*; import java.net.URLEncoder; +import java.time.format.DateTimeFormatter; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -10,7 +12,13 @@ import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.builder.ExcelWriterBuilder; import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.fill.FillConfig; +import com.alibaba.excel.write.metadata.fill.FillWrapper; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.ShiroUtils; +import com.ruoyi.common.utils.file.FileDownloadUtils; import com.ruoyi.financial.domain.FinancialReceivablesRecords; +import com.ruoyi.financial.domain.VO.ExportFinancialReceivablesVo; import com.ruoyi.financial.service.IFinancialReceivablesRecordsService; import org.apache.avalon.framework.service.ServiceException; import org.apache.poi.ss.usermodel.*; @@ -153,42 +161,49 @@ public class FinancialReceivablesController extends BaseController @GetMapping("/excelReceivablesVoucher/{financialReceivablesId}") public void excelReceivablesVoucher(@PathVariable("financialReceivablesId") Long financialReceivablesId,HttpServletResponse response) throws IOException { FinancialReceivables financialReceivables = financialReceivablesService.selectFinancialReceivablesById(financialReceivablesId); + List financialReceivablesRecordsList = receivablesRecordsService.selectFinancialReceivablesRecordsListByCode(financialReceivables.getFinancialReceivablesCode()); +// +// Map map = financialReceivablesService.exportTemplate(financialReceivablesRecordsList); + Map map1 = new HashMap<>(); + map1.put("debitAccount",financialReceivables.getDebitAccount()); + String date = DateUtils.getDate(); + String[] dateArray = date.split("-"); + map1.put("year", dateArray[0]); + map1.put("month", dateArray[1]); + map1.put("day", dateArray[2]); + map1.put("openBank",financialReceivables.getOpenBank()); + map1.put("debitAccount",financialReceivables.getDebitAccount()); + map1.put("loginName", ShiroUtils.getLoginName()); - financialReceivablesService.exportTemplate(financialReceivablesId); // 模版位置 String name = "FinancialReceiptVoucherTemplate.xlsx"; + FileDownloadUtils fileDownloadUtils = new FileDownloadUtils(); + //获取文件的绝对路径 + String fileAbsolutePath = fileDownloadUtils.getFileAbsolutePath(name); + String fileName = DateUtils.dateTimeNow() + financialReceivables.getFinancialReceivablesCode() +"收款凭证.xlsx"; // 设置响应头,指定文件名和文件类型 - response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("attachments/FinancialReceiptVoucher.xlsx", "UTF-8")); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); response.setContentType("application/octet-stream"); - - InputStream inputStream = null; - try { - // 获取模板文件的输入流 - inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name); - - if (inputStream == null) { - throw new FileNotFoundException("模板文件未找到:" + name); - } - - // 创建一个ExcelWriterBuilder对象,并指定输出流和输入流 - ExcelWriterBuilder writerBuilder = EasyExcel.write(response.getOutputStream()); - + // 获取模板文件的输入流,引用绝对路径上的模版 + // 创建一个ExcelWriterBuilder对象,并指定输出流和输入流 + // 每页最多显示的行数 + ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(fileAbsolutePath).build(); + final int maxRowsPerPage = 6; + // 计算需要多少页 + int totalPages = (int) Math.ceil((double) financialReceivablesRecordsList.size() / maxRowsPerPage); + for (int i = 0; i < totalPages; i++) { + List financialReceivablesRecordsListPage = + receivablesRecordsService.selectFinancialReceivablesRecordsListByCodePage(financialReceivables.getFinancialReceivablesCode(), i + 1, maxRowsPerPage); + Map map = financialReceivablesService.exportTemplate(financialReceivablesRecordsList); // 创建一个WriteSheet对象,并指定模板中的Sheet编号 - WriteSheet writeSheet = EasyExcel.writerSheet(0).build(); - - // 将数据写入Excel文件 - writerBuilder.withTemplate(inputStream).sheet("sheet1").doFill(financialReceivables); - - } finally { - // 关闭输入流 - if (inputStream != null) { - inputStream.close(); - } + WriteSheet writeSheet = EasyExcel.writerSheet("sheet" + (i + 1)).build(); + FillConfig fillConfig = FillConfig.builder().forceNewRow(false).build(); + excelWriter.fill(map1, writeSheet); + excelWriter.fill(map.get("list"), fillConfig, writeSheet); + excelWriter.fill(map.get("amount"), writeSheet); } - - // 刷新输出流 - response.flushBuffer(); + excelWriter.finish(); } /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/financial/domain/VO/ExportFinancialReceivablesVo.java b/ruoyi-admin/src/main/java/com/ruoyi/financial/domain/VO/ExportFinancialReceivablesVo.java new file mode 100644 index 00000000..bc94139e --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/financial/domain/VO/ExportFinancialReceivablesVo.java @@ -0,0 +1,37 @@ +package com.ruoyi.financial.domain.VO; + +import lombok.Data; + +/** +* 导出 财务应收账款模版 +* */ +@Data +public class ExportFinancialReceivablesVo { + + /*收款摘要*/ + private String receivablesAbstract; + + //生成亿到分的私有成员变量 + private String yi; + + private String qianw; + + private String baiw; + + private String shiw; + + private String wan; + + private String qian; + + private String bai; + + private String shi; + + private String yuan; + + private String jiao; + + private String fen; + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/financial/mapper/FinancialReceivablesRecordsMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/financial/mapper/FinancialReceivablesRecordsMapper.java index 7c8b8779..0b56f1af 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/financial/mapper/FinancialReceivablesRecordsMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/financial/mapper/FinancialReceivablesRecordsMapper.java @@ -1,6 +1,8 @@ package com.ruoyi.financial.mapper; import java.util.List; +import java.util.Map; + import com.ruoyi.financial.domain.FinancialReceivablesRecords; /** @@ -82,4 +84,6 @@ public interface FinancialReceivablesRecordsMapper * @return 财务应收账款记录集合 */ List selectFinancialReceivablesRecordsListByCode(String financialReceivablesCode); + + List selectFinancialReceivablesRecordsListByCodePage(Map paramsMap); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesRecordsService.java b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesRecordsService.java index 150c7722..e1f6d2fb 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesRecordsService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesRecordsService.java @@ -77,4 +77,7 @@ public interface IFinancialReceivablesRecordsService * 根据应收单号查找对应的收款记录 * */ List selectFinancialReceivablesRecordsListByCode(String financialReceivablesCode); + + + List selectFinancialReceivablesRecordsListByCodePage(String financialReceivablesCode, int pageNum, int pageSize); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesService.java b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesService.java index 05d5fa31..efbb0460 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesService.java @@ -1,9 +1,13 @@ package com.ruoyi.financial.service; +import java.io.IOException; import java.util.List; import java.util.Map; import com.ruoyi.financial.domain.FinancialReceivables; +import com.ruoyi.financial.domain.FinancialReceivablesRecords; + +import javax.servlet.http.HttpServletResponse; /** * 财务应收账款Service接口 @@ -95,5 +99,6 @@ public interface IFinancialReceivablesService */ Map exportReceivables(FinancialReceivables financialReceivables); - Map exportTemplate(Long financialReceivablesId); + Map exportTemplate(List financialReceivablesRecordsList) throws IOException; + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesRecordsServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesRecordsServiceImpl.java index 1670bad0..4df94175 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesRecordsServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesRecordsServiceImpl.java @@ -1,6 +1,8 @@ package com.ruoyi.financial.service.impl; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; @@ -141,4 +143,14 @@ public class FinancialReceivablesRecordsServiceImpl implements IFinancialReceiva } return financialReceivablesRecordsList; } + + @Override + public List selectFinancialReceivablesRecordsListByCodePage(String financialReceivablesCode, int pageNum, int pageSize) { + + Map map = new HashMap<>(); + map.put("code",financialReceivablesCode); + map.put("start",pageNum); + map.put("pageSize",pageSize); + return financialReceivablesRecordsMapper.selectFinancialReceivablesRecordsListByCodePage(map); + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesServiceImpl.java index 09ec2077..d7ed638d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesServiceImpl.java @@ -1,15 +1,24 @@ package com.ruoyi.financial.service.impl; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URLEncoder; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.write.builder.ExcelWriterBuilder; +import com.alibaba.excel.write.metadata.WriteSheet; import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.financial.domain.FinancialReceivablesRecords; +import com.ruoyi.financial.domain.VO.ExportFinancialReceivablesVo; import com.ruoyi.financial.domain.VO.FinancialReceivablesRecordsVO; import com.ruoyi.financial.mapper.FinancialReceivablesRecordsMapper; import com.ruoyi.system.domain.SysCustomerVo; @@ -28,6 +37,8 @@ import com.ruoyi.common.core.text.Convert; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.NumberUtils; +import javax.servlet.http.HttpServletResponse; + /** * 财务应收账款Service业务层处理 * @@ -308,33 +319,55 @@ public class FinancialReceivablesServiceImpl implements IFinancialReceivablesSer /*设置导出模板数据*/ @Override - public Map exportTemplate(Long id) throws NoSuchBeanDefinitionException { + public Map exportTemplate(List financialReceivablesRecordsList) throws NoSuchBeanDefinitionException, IOException { Map map = new HashMap<>(); - //需要传输导出的值有:借方科目,开户银行,年,月,日, + //需要传输导出的值有:借方科目,开户银行, + //现在时间截取后 年,月,日, 格式为转换 yyyy MM dd, //凭证信息批量:包含收款摘要,金额字符串截取,位数从亿开始,亿,千万,百万,十万,万,千,百,十,元,角,分。小数点后俩位为角,分,小数点不需要显示, //将以上信息通过map传输出去 - FinancialReceivables financialReceivables = financialReceivablesMapper.selectFinancialReceivablesById(id); - List> financialReceivablesRecordsAmountList = new ArrayList<>(); + BigDecimal amount = BigDecimal.ZERO; + List list = new ArrayList<>(); + String date = DateUtils.getDate(); + String[] dateArray = date.split("-"); + map.put("year", dateArray[0]); + map.put("month", dateArray[1]); + map.put("day", dateArray[2]); //接收拆分的数字 - FinancialReceivablesRecords financialReceivablesRecords = new FinancialReceivablesRecords(); - List financialReceivablesRecordsList = receivablesRecordsMapper.selectFinancialReceivablesRecordsListByCode(financialReceivables.getFinancialReceivablesCode()); for (FinancialReceivablesRecords financialReceivablesRecord : financialReceivablesRecordsList) { - + //对于财务分割的数据,需要合计。 + if (financialReceivablesRecord.getReceivablesPrice() != null){ + amount = amount.add(financialReceivablesRecord.getReceivablesPrice().setScale(2, BigDecimal.ROUND_HALF_UP)); + }else if (financialReceivablesRecord.getReceivablesPrice() == null){ + continue; + } + ExportFinancialReceivablesVo exportFinancialReceivablesVo1 = splitNumber(financialReceivablesRecord); + String receivablesAbstract = financialReceivablesRecord.getReceivablesAbstract(); + //收款摘要 + exportFinancialReceivablesVo1.setReceivablesAbstract(receivablesAbstract); + list.add(exportFinancialReceivablesVo1); } + map.put("list",list); + FinancialReceivablesRecords financialReceivablesRecord = new FinancialReceivablesRecords(); + financialReceivablesRecord.setReceivablesPrice(amount); + map.put("amount",splitNumber(financialReceivablesRecord)); + map.put("loginName",ShiroUtils.getLoginName()); return map; } /*切割返回数字*/ - public Map splitNumber(FinancialReceivablesRecords financialReceivablesRecord) { - Map map = new HashMap<>(); + public ExportFinancialReceivablesVo splitNumber(FinancialReceivablesRecords financialReceivablesRecord) { + Map map = new HashMap<>(); + ExportFinancialReceivablesVo exportFinancialReceivablesVo = new ExportFinancialReceivablesVo(); /*获取当前传输过来的*/ - Map map1 = new HashMap<>(); List result = new ArrayList<>(); List units = Arrays.asList("亿", "千万", "百万", "十万", "万", "千", "百", "十", "元", "角", "分"); List unitKey = Arrays.asList("fen", "jiao", "yuan", "shi", "bai", "qian", "wan", "shiw", "baiw", "qianw", "yi"); - BigDecimal amount = financialReceivablesRecord.getReceivablesPrice().setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal amount = financialReceivablesRecord.getReceivablesPrice(); String integerPart = amount.toBigInteger().toString(); // 获取整数部分 String decimalPart = amount.remainder(BigDecimal.ONE).multiply(new BigDecimal(100)).toBigInteger().toString(); // 获取小数部分(角分) int unitIndex = 0; + for (int i = 0; i < unitKey.size() - 1; i++) { + map.put(unitKey.get(i), ""); + } for (int i = integerPart.length() - 1; i >= 0; i--) { char digit = integerPart.charAt(i); if (digit != '0' || !units.get(unitIndex).isEmpty()) {result.add(0, String.valueOf(digit));} @@ -347,17 +380,21 @@ public class FinancialReceivablesServiceImpl implements IFinancialReceivablesSer result.add(decimalPart.substring(1, 2)); /*根据长度设备map中的Stirng参数,调用对等获取实现map*/ for (int i = 0; i < result.size(); i++) { - String unitKeyValue = unitKey.get(result.size() - i); - map1.put(unitKeyValue,result.get(i)); - } - for (int j = result.size() - 1 ; j < unitKey.size(); j ++){ - map1.put(unitKey.get(j),""); + String unitKeyValue = unitKey.get((result.size() -1) - i); + map.put(unitKeyValue,result.get(i)); } - //收款摘要 - map.put("receivablesAbstract",financialReceivablesRecord.getReceivablesAbstract()); + exportFinancialReceivablesVo.setYi(map.get("yi")); + exportFinancialReceivablesVo.setQianw(map.get("qianw")); + exportFinancialReceivablesVo.setBaiw(map.get("baiw")); + exportFinancialReceivablesVo.setShi(map.get("shiw")); + exportFinancialReceivablesVo.setWan(map.get("wan")); + exportFinancialReceivablesVo.setQian(map.get("qian")); + exportFinancialReceivablesVo.setBai(map.get("bai")); + exportFinancialReceivablesVo.setShi(map.get("shi")); + exportFinancialReceivablesVo.setYuan(map.get("yuan")); + exportFinancialReceivablesVo.setJiao(map.get("jiao")); + exportFinancialReceivablesVo.setFen(map.get("fen")); //金额对象 - map.put("receivablesPrice",map1); - return map; + return exportFinancialReceivablesVo; } - } diff --git a/ruoyi-admin/src/main/resources/attachments/FinancialReceiptVoucherTemplate.xlsx b/ruoyi-admin/src/main/resources/attachments/FinancialReceiptVoucherTemplate.xlsx index 36d76bd4..e87fcd65 100644 Binary files a/ruoyi-admin/src/main/resources/attachments/FinancialReceiptVoucherTemplate.xlsx and b/ruoyi-admin/src/main/resources/attachments/FinancialReceiptVoucherTemplate.xlsx differ diff --git a/ruoyi-admin/src/main/resources/mapper/financial/FinancialReceivablesRecordsMapper.xml b/ruoyi-admin/src/main/resources/mapper/financial/FinancialReceivablesRecordsMapper.xml index 4e655b33..95f1e96e 100644 --- a/ruoyi-admin/src/main/resources/mapper/financial/FinancialReceivablesRecordsMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/financial/FinancialReceivablesRecordsMapper.xml @@ -35,7 +35,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where financial_receivables_code = #{financialReceivablesCode} - +