|
@@ -1,9 +1,12 @@
|
|
|
package com.ydtech.modules.inv.utils;
|
|
package com.ydtech.modules.inv.utils;
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
import com.alibaba.excel.util.ListUtils;
|
|
import com.alibaba.excel.util.ListUtils;
|
|
|
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
|
|
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
|
|
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
|
|
+import com.alipay.api.internal.util.file.IOUtils;
|
|
|
import com.ydtech.constants.enums.inv.InvPayMethodEnum;
|
|
import com.ydtech.constants.enums.inv.InvPayMethodEnum;
|
|
|
import com.ydtech.modules.inv.model.*;
|
|
import com.ydtech.modules.inv.model.*;
|
|
|
import com.ydtech.modules.inv.model.excel.InvSettlementSourceExcel;
|
|
import com.ydtech.modules.inv.model.excel.InvSettlementSourceExcel;
|
|
@@ -15,10 +18,7 @@ import lombok.SneakyThrows;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.io.InputStream;
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
@@ -249,88 +249,95 @@ public class EasyExcelUtils {
|
|
|
inputStream.close();
|
|
inputStream.close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 初始化一个空的列表用于存储已更新的对象
|
|
|
|
|
+ List<InvAccountExcel> updatedList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
+ String fileName = "综合资金申请单" + System.currentTimeMillis() + ".xlsx";
|
|
|
|
|
+ String filePath = uploadFilePath + fileName;
|
|
|
|
|
+ Map<String, String> placeholders = new HashMap<>();
|
|
|
|
|
|
|
|
- List<InvAccountExcel> list = new ArrayList<>();
|
|
|
|
|
- // 获取工作表并填充
|
|
|
|
|
- for (InvAccountExcel excel : invAccountExcel) {
|
|
|
|
|
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
|
|
|
|
- // 写入文件
|
|
|
|
|
- Date date = new Date();
|
|
|
|
|
- String file = date.getTime() + ".xlsx";
|
|
|
|
|
- String fileName = uploadFilePath + file;
|
|
|
|
|
|
|
+ for (int i = 0; i < invAccountExcel.size(); i++) {
|
|
|
|
|
+ InvAccountExcel excel = invAccountExcel.get(i);
|
|
|
|
|
+
|
|
|
|
|
+ // 格式化申请时间
|
|
|
excel.setExcelApplyTime(new SimpleDateFormat("yyyy-MM-dd").format(excel.getApplyTime()));
|
|
excel.setExcelApplyTime(new SimpleDateFormat("yyyy-MM-dd").format(excel.getApplyTime()));
|
|
|
|
|
+
|
|
|
|
|
+ // 处理支付方式
|
|
|
String payMethod = excel.getPayMethod();
|
|
String payMethod = excel.getPayMethod();
|
|
|
String[] split = payMethod.split(",");
|
|
String[] split = payMethod.split(",");
|
|
|
- StringBuilder a = new StringBuilder();
|
|
|
|
|
- for (int i = 0; i < split.length; i++) {
|
|
|
|
|
- a.append(InvPayMethodEnum.getNameByCode(split[i]));
|
|
|
|
|
- if (i < split.length - 1) {
|
|
|
|
|
- a.append(",");
|
|
|
|
|
|
|
+ StringBuilder payMethodStr = new StringBuilder();
|
|
|
|
|
+ for (int j = 0; j < split.length; j++) {
|
|
|
|
|
+ payMethodStr.append(InvPayMethodEnum.getNameByCode(split[j]));
|
|
|
|
|
+ if (j < split.length - 1) {
|
|
|
|
|
+ payMethodStr.append(",");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ excel.setPayMethod(payMethodStr.toString());
|
|
|
|
|
|
|
|
- StringBuilder stringBuffer = new StringBuilder();
|
|
|
|
|
|
|
+ // 处理利润分配
|
|
|
|
|
+ StringBuilder plateStr = new StringBuilder();
|
|
|
|
|
+ Map<String, List<InvAccountProfit>> collect = invAccountProfit.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(InvAccountProfit::getProfitEng));
|
|
|
|
|
|
|
|
- Map<String, List<InvAccountProfit>> collect = invAccountProfit.stream().collect(
|
|
|
|
|
- Collectors.groupingBy(
|
|
|
|
|
- InvAccountProfit::getProfitEng
|
|
|
|
|
- ));
|
|
|
|
|
-
|
|
|
|
|
- for (Map.Entry<String, Object> entry : excel.getOutProfit().entrySet()) {
|
|
|
|
|
|
|
+ // 处理输出利润
|
|
|
|
|
+ for (Map.Entry<String, Object> outEntry : excel.getOutProfit().entrySet()) {
|
|
|
try {
|
|
try {
|
|
|
- double value = Double.parseDouble(entry.getValue().toString());
|
|
|
|
|
|
|
+ double value = Double.parseDouble(outEntry.getValue().toString());
|
|
|
if (value != 0) {
|
|
if (value != 0) {
|
|
|
- stringBuffer.append(collect.get(entry.getKey()).get(0).getProfitName()).append(" ").append(value);
|
|
|
|
|
|
|
+ plateStr.append(collect.get(outEntry.getKey()).get(0).getProfitName()).append(" ").append(value);
|
|
|
}
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
} catch (NumberFormatException e) {
|
|
|
- // 处理转换异常
|
|
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- stringBuffer.append("→");
|
|
|
|
|
|
|
+ plateStr.append("→");
|
|
|
|
|
|
|
|
- for (Map.Entry<String, Object> entry : excel.getEntProfit().entrySet()) {
|
|
|
|
|
|
|
+ // 处理进入利润
|
|
|
|
|
+ for (Map.Entry<String, Object> entEntry : excel.getEntProfit().entrySet()) {
|
|
|
try {
|
|
try {
|
|
|
- double value = Double.parseDouble(entry.getValue().toString());
|
|
|
|
|
|
|
+ double value = Double.parseDouble(entEntry.getValue().toString());
|
|
|
if (value != 0) {
|
|
if (value != 0) {
|
|
|
- stringBuffer.append(collect.get(entry.getKey()).get(0).getProfitName()).append(" ").append(value);
|
|
|
|
|
|
|
+ plateStr.append(collect.get(entEntry.getKey()).get(0).getProfitName()).append(" ").append(value);
|
|
|
}
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
} catch (NumberFormatException e) {
|
|
|
- // 处理转换异常
|
|
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- excel.setPlate(stringBuffer.toString());
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- excel.setPayMethod(a.toString());
|
|
|
|
|
- // 生成工作簿对象
|
|
|
|
|
- ExcelWriterBuilder workBookWriter = EasyExcel.write(fileName, InvAccountExcel.class)
|
|
|
|
|
- .withTemplate(byteArrayInputStream);
|
|
|
|
|
-
|
|
|
|
|
- workBookWriter.sheet().doFill(excel);
|
|
|
|
|
- excel.setUplodePath(file);
|
|
|
|
|
- excel.setPayMethod(payMethod);
|
|
|
|
|
- list.add(excel);
|
|
|
|
|
- byteArrayInputStream.close();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ excel.setPlate(plateStr.toString());
|
|
|
|
|
+
|
|
|
|
|
+ // 准备占位符
|
|
|
|
|
+ placeholders.put("company" + i, excel.getCompany());
|
|
|
|
|
+ placeholders.put("excelAccountOperateId" + i, String.valueOf(excel.getExcelAccountOperateId()));
|
|
|
|
|
+ placeholders.put("applicant" + i, excel.getApplicant());
|
|
|
|
|
+ placeholders.put("applySector" + i, excel.getApplySector());
|
|
|
|
|
+ placeholders.put("excelApplyTime" + i, excel.getExcelApplyTime());
|
|
|
|
|
+ placeholders.put("collectionMessage" + i, excel.getCollectionMessage());
|
|
|
|
|
+ placeholders.put("fundFlow" + i, excel.getFundFlow());
|
|
|
|
|
+ placeholders.put("plate" + i, excel.getPlate());
|
|
|
|
|
+ placeholders.put("fundUse" + i, excel.getFundUse());
|
|
|
|
|
+ placeholders.put("remark" + i, excel.getRemark());
|
|
|
|
|
+ placeholders.put("applyAmount" + i, String.valueOf(excel.getApplyAmount()));
|
|
|
|
|
+ placeholders.put("bigApplyAmount" + i, excel.getBigApplyAmount());
|
|
|
|
|
+ placeholders.put("payMethod" + i, excel.getPayMethod());
|
|
|
|
|
+
|
|
|
|
|
+ // 设置上传路径和支付方式等信息
|
|
|
|
|
+ excel.setUplodePath(fileName);
|
|
|
|
|
+ excel.setPayMethod(payMethod); // 保持原始支付方式不变
|
|
|
|
|
+
|
|
|
|
|
+ // 添加到已更新的列表中
|
|
|
|
|
+ updatedList.add(excel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- insAccountExcelService.updateBatchById(list);
|
|
|
|
|
|
|
+ // 从bytes数组创建新的输入流
|
|
|
|
|
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
|
|
|
|
+ EasyExcel.write(filePath).withTemplate(byteArrayInputStream).sheet().doFill(placeholders);
|
|
|
|
|
|
|
|
- File[] srcFiles = new File[list.size()];
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- srcFiles[i] = new File(uploadFilePath + list.get(i).getUplodePath());
|
|
|
|
|
- }
|
|
|
|
|
- String a = LocalDate.now() + ".zip";
|
|
|
|
|
- File zipFile = new File(uploadFilePath + a);
|
|
|
|
|
- // 调用压缩方法
|
|
|
|
|
- zipFiles(srcFiles, zipFile);
|
|
|
|
|
|
|
+ // 更新数据库中的记录
|
|
|
|
|
+ insAccountExcelService.updateBatchById(updatedList);
|
|
|
|
|
|
|
|
- return a;
|
|
|
|
|
|
|
+ return fileName;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|