Browse Source

修改:新增导出模版信息,添批量固定数量的收款凭证明细。最大数量为6,计算为6个合计,超出新增sheer表。

dev
zhangsiqi 3 months ago
parent
commit
cfbee39afb
  1. 71
      ruoyi-admin/src/main/java/com/ruoyi/financial/controller/FinancialReceivablesController.java
  2. 37
      ruoyi-admin/src/main/java/com/ruoyi/financial/domain/VO/ExportFinancialReceivablesVo.java
  3. 4
      ruoyi-admin/src/main/java/com/ruoyi/financial/mapper/FinancialReceivablesRecordsMapper.java
  4. 3
      ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesRecordsService.java
  5. 7
      ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesService.java
  6. 12
      ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesRecordsServiceImpl.java
  7. 79
      ruoyi-admin/src/main/java/com/ruoyi/financial/service/impl/FinancialReceivablesServiceImpl.java
  8. BIN
      ruoyi-admin/src/main/resources/attachments/FinancialReceiptVoucherTemplate.xlsx
  9. 5
      ruoyi-admin/src/main/resources/mapper/financial/FinancialReceivablesRecordsMapper.xml
  10. 8
      ruoyi-admin/src/main/resources/templates/financial/receivables/addReceivablesVoucher.html
  11. 36
      ruoyi-admin/src/main/resources/templates/financial/receivables/addReceivablesVoucherNoSales.html

71
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<FinancialReceivablesRecords> financialReceivablesRecordsList = receivablesRecordsService.selectFinancialReceivablesRecordsListByCode(financialReceivables.getFinancialReceivablesCode());
//
// Map<String, Object> map = financialReceivablesService.exportTemplate(financialReceivablesRecordsList);
Map<String, Object> 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<FinancialReceivablesRecords> financialReceivablesRecordsListPage =
receivablesRecordsService.selectFinancialReceivablesRecordsListByCodePage(financialReceivables.getFinancialReceivablesCode(), i + 1, maxRowsPerPage);
Map<String, Object> 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();
}
/**

37
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;
}

4
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<FinancialReceivablesRecords> selectFinancialReceivablesRecordsListByCode(String financialReceivablesCode);
List<FinancialReceivablesRecords> selectFinancialReceivablesRecordsListByCodePage(Map<String, Object> paramsMap);
}

3
ruoyi-admin/src/main/java/com/ruoyi/financial/service/IFinancialReceivablesRecordsService.java

@ -77,4 +77,7 @@ public interface IFinancialReceivablesRecordsService
* 根据应收单号查找对应的收款记录
* */
List<FinancialReceivablesRecords> selectFinancialReceivablesRecordsListByCode(String financialReceivablesCode);
List<FinancialReceivablesRecords> selectFinancialReceivablesRecordsListByCodePage(String financialReceivablesCode, int pageNum, int pageSize);
}

7
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<String, Object> exportReceivables(FinancialReceivables financialReceivables);
Map<String,Object> exportTemplate(Long financialReceivablesId);
Map<String, Object> exportTemplate(List<FinancialReceivablesRecords> financialReceivablesRecordsList) throws IOException;
}

12
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<FinancialReceivablesRecords> selectFinancialReceivablesRecordsListByCodePage(String financialReceivablesCode, int pageNum, int pageSize) {
Map<String,Object> map = new HashMap<>();
map.put("code",financialReceivablesCode);
map.put("start",pageNum);
map.put("pageSize",pageSize);
return financialReceivablesRecordsMapper.selectFinancialReceivablesRecordsListByCodePage(map);
}
}

79
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<String, Object> exportTemplate(Long id) throws NoSuchBeanDefinitionException {
public Map<String, Object> exportTemplate(List<FinancialReceivablesRecords> financialReceivablesRecordsList) throws NoSuchBeanDefinitionException, IOException {
Map<String, Object> map = new HashMap<>();
//需要传输导出的值有:借方科目,开户银行,年,月,日,
//需要传输导出的值有:借方科目,开户银行,
//现在时间截取后 年,月,日, 格式为转换 yyyy MM dd,
//凭证信息批量:包含收款摘要,金额字符串截取,位数从亿开始,亿,千万,百万,十万,万,千,百,十,元,角,分。小数点后俩位为角,分,小数点不需要显示,
//将以上信息通过map传输出去
FinancialReceivables financialReceivables = financialReceivablesMapper.selectFinancialReceivablesById(id);
List<Map<String, Object>> financialReceivablesRecordsAmountList = new ArrayList<>();
BigDecimal amount = BigDecimal.ZERO;
List<ExportFinancialReceivablesVo> 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<FinancialReceivablesRecords> 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<String, Object> splitNumber(FinancialReceivablesRecords financialReceivablesRecord) {
Map<String, Object> map = new HashMap<>();
public ExportFinancialReceivablesVo splitNumber(FinancialReceivablesRecords financialReceivablesRecord) {
Map<String, String> map = new HashMap<>();
ExportFinancialReceivablesVo exportFinancialReceivablesVo = new ExportFinancialReceivablesVo();
/*获取当前传输过来的*/
Map<String, Object> map1 = new HashMap<>();
List<String> result = new ArrayList<>();
List<String> units = Arrays.asList("亿", "千万", "百万", "十万", "万", "千", "百", "十", "元", "角", "分");
List<String> 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;
}
}

BIN
ruoyi-admin/src/main/resources/attachments/FinancialReceiptVoucherTemplate.xlsx

Binary file not shown.

5
ruoyi-admin/src/main/resources/mapper/financial/FinancialReceivablesRecordsMapper.xml

@ -35,7 +35,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectFinancialReceivablesRecordsVo"/>
where financial_receivables_code = #{financialReceivablesCode}
</select>
<select id="selectFinancialReceivablesRecordsListByCodePage" parameterType="map" resultMap="FinancialReceivablesRecordsResult">
<include refid="selectFinancialReceivablesRecordsVo"/>
where financial_receivables_code = #{code} limit #{start} offset #{pageSize}
</select>
<select id="selectFinancialReceivablesRecordsById" parameterType="Long" resultMap="FinancialReceivablesRecordsResult">
<include refid="selectFinancialReceivablesRecordsVo"/>

8
ruoyi-admin/src/main/resources/templates/financial/receivables/addReceivablesVoucher.html

@ -283,7 +283,13 @@
editable : {type: 'date', clear: false, title: '请选择日期:'}
},
{title: '收款金额', field: 'receivablesPrice',
editable: {type: 'text',},
editable: {type: 'text',
validate: function(v){
if (!/^[0-9]+(\.[0-9]{1,2})?$/.test(v)) {
return '收款金额只能为数字,最多保留两位小数';
}
}
},
},
{title: '收款摘要', field: 'receivablesAbstract',
editable: {type: 'text',},

36
ruoyi-admin/src/main/resources/templates/financial/receivables/addReceivablesVoucherNoSales.html

@ -181,22 +181,10 @@
showSearch:false,
queryParams:queryParams,
columns: [
{
title: '财务应收账款记录id',
field: 'receivablesRecordsId',
visible: false
},
{
title: '操作时间',
field: 'operatingTime',
},
{
title: '摘要',
field: 'receivablesAbstract',
},
{
title: '收款金额',
field: 'receivablesPrice',
{title: '财务应收账款记录id', field: 'receivablesRecordsId', visible: false},
{title: '操作时间', field: 'operatingTime',},
{title: '摘要', field: 'receivablesAbstract',},
{title: '收款金额', field: 'receivablesPrice',
formatter: function(value, row, index) {
// 格式化收款金额为保留两位小数的字符串
return parseFloat(value).toFixed(2);
@ -219,12 +207,7 @@
// 生成一个简单的唯一标识,这里使用时间戳作为示例
var uniqueId = new Date().getTime();
// 创建一个新行数据模板,这里仅为示例,具体根据表格列来定义
var newRow = {
receivablesRecordsId:uniqueId,
receivablesAbstract: "",
receivablesPrice: "",
};
var newRow = {receivablesRecordsId:uniqueId, receivablesAbstract: "", receivablesPrice: "",};
// 使用Bootstrap Table的API插入新行
$('#bootstrap-receivablesVoucher-table').bootstrapTable('append', newRow);
@ -244,7 +227,14 @@
{checkbox: false},
{title: '财务应收账款记录id', field: 'receivablesRecordsId', visible: false},
{title: '收款摘要', field: 'receivablesAbstract', editable: {type: 'text',},},
{title: '收款金额', field: 'receivablesPrice', editable: {type: 'text',},},
{title: '收款金额', field: 'receivablesPrice',
editable: {type: 'text',
validate: function(v){
if (!/^[0-9]+(\.[0-9]{1,2})?$/.test(v)) {
return '收款金额只能为数字,最多保留两位小数';
}
}
},},
{title: '操作', align: 'center',
formatter: function(value, row, index) {
var actions = [];

Loading…
Cancel
Save