|
@@ -14,7 +14,9 @@ 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.File;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
@@ -230,12 +232,22 @@ public class EasyExcelUtils {
|
|
|
*/
|
|
*/
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
|
public String downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel, List<InvAccountProfit> invAccountProfit) {
|
|
public String downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel, List<InvAccountProfit> invAccountProfit) {
|
|
|
|
|
+
|
|
|
// 加载模板
|
|
// 加载模板
|
|
|
InputStream inputStream = getClass().getResourceAsStream("/template/资金申请单模板.xlsx");
|
|
InputStream inputStream = getClass().getResourceAsStream("/template/资金申请单模板.xlsx");
|
|
|
|
|
|
|
|
|
|
+ byte[] bytes = saveaIns(inputStream);
|
|
|
|
|
+
|
|
|
|
|
+ if (inputStream != null) {
|
|
|
|
|
+ inputStream.close();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
List<InvAccountExcel> list = new ArrayList<>();
|
|
List<InvAccountExcel> list = new ArrayList<>();
|
|
|
// 获取工作表并填充
|
|
// 获取工作表并填充
|
|
|
for (InvAccountExcel excel : invAccountExcel) {
|
|
for (InvAccountExcel excel : invAccountExcel) {
|
|
|
|
|
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
|
|
// 写入文件
|
|
// 写入文件
|
|
|
Date date = new Date();
|
|
Date date = new Date();
|
|
|
String file = date.getTime() + ".xlsx";
|
|
String file = date.getTime() + ".xlsx";
|
|
@@ -275,13 +287,16 @@ public class EasyExcelUtils {
|
|
|
excel.setPayMethod(a.toString());
|
|
excel.setPayMethod(a.toString());
|
|
|
// 生成工作簿对象
|
|
// 生成工作簿对象
|
|
|
ExcelWriterBuilder workBookWriter = EasyExcel.write(fileName, InvAccountExcel.class)
|
|
ExcelWriterBuilder workBookWriter = EasyExcel.write(fileName, InvAccountExcel.class)
|
|
|
- .withTemplate(inputStream);
|
|
|
|
|
|
|
+ .withTemplate(byteArrayInputStream);
|
|
|
|
|
|
|
|
workBookWriter.sheet().doFill(excel);
|
|
workBookWriter.sheet().doFill(excel);
|
|
|
excel.setUplodePath(file);
|
|
excel.setUplodePath(file);
|
|
|
excel.setPayMethod(payMethod);
|
|
excel.setPayMethod(payMethod);
|
|
|
list.add(excel);
|
|
list.add(excel);
|
|
|
|
|
+ byteArrayInputStream.close();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
insAccountExcelService.updateBatchById(list);
|
|
insAccountExcelService.updateBatchById(list);
|
|
|
|
|
|
|
|
File[] srcFiles = new File[list.size()];
|
|
File[] srcFiles = new File[list.size()];
|
|
@@ -296,4 +311,18 @@ public class EasyExcelUtils {
|
|
|
return a;
|
|
return a;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //保存流对象(输入流在第二次使用的时候会失效)
|
|
|
|
|
+ public byte[] saveaIns(InputStream ins){
|
|
|
|
|
+ byte[] buf = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ if(ins!=null){
|
|
|
|
|
+ buf = org.apache.commons.io.IOUtils.toByteArray(ins);//ins为InputStream流
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return buf;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|