开票文件下载处理文件添加多线程处理任务

product
chuang 2 years ago
parent bf66688753
commit ed9dc09581

@ -76,6 +76,9 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -149,7 +152,8 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
@Autowired @Autowired
private Receiptin_item0Service receiptin_item0Service; private Receiptin_item0Service receiptin_item0Service;
public void getExcel(List<HashMap<String, Object>> list, String templateFilePath,String settlements,BigDecimal amount) throws Exception { public void getExcel(List<HashMap<String, Object>> list, String templateFilePath,String settlements,ArrayList<BigDecimal> amountt) throws Exception {
BigDecimal amount = amountt.get(0);
//声明要创建的文件名 //声明要创建的文件名
String filename = templateFilePath + "\\废钢收货明细表("+settlements+"吨).xls"; String filename = templateFilePath + "\\废钢收货明细表("+settlements+"吨).xls";
//创建 HSSFWorkbook 类的实例 //创建 HSSFWorkbook 类的实例
@ -605,10 +609,67 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
List<HashMap<String, Object>> vehicleInfo = purchaseorderitemMapper.getVehicleInfo(wrapper); List<HashMap<String, Object>> vehicleInfo = purchaseorderitemMapper.getVehicleInfo(wrapper);
List<HashMap<String, Object>> titleInfo = purchaseorderitemMapper.getTitleInfo(wrapper); List<HashMap<String, Object>> titleInfo = purchaseorderitemMapper.getTitleInfo(wrapper);
String settlement = String.valueOf(titleInfo.get(0).get("settlement")); String settlement = String.valueOf(titleInfo.get(0).get("settlement"));
this.getPdf(wrapper, templateFilePath,settlement);
this.getWord(info, templateFilePath,settlement);
this.getExcel(info, templateFilePath,settlement,amount);
this.getVehicle(vehicleInfo, templateFilePath,settlement); // 任务集合
// 子线程计数器
CountDownLatch countDownLatch = new CountDownLatch(4);
// 创建线程池
ExecutorService executorService = Executors.newFixedThreadPool(4);
try {
executorService.execute(() -> {
try {
this.getPdf(wrapper, templateFilePath,settlement);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
executorService.execute(() -> {
try {
this.getWord(info, templateFilePath,settlement);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
ArrayList<BigDecimal> bigDecimals = new ArrayList<>();
bigDecimals.add(amount);
executorService.execute(() -> {
try {
this.getExcel(info, templateFilePath,settlement,bigDecimals);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
executorService.execute(() -> {
try {
this.getVehicle(vehicleInfo, templateFilePath,settlement);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 关闭子线程
countDownLatch.countDown();
});
// 等待所有子线程执行完
countDownLatch.await();
} catch (Exception e) {
log.error("等待所有子线程执行完发生错误:" + e.getMessage());
e.printStackTrace();
} finally {
// 线程池不接受新任务
executorService.shutdown();
}
this.getZIP(templateFilePath, response,settlement); this.getZIP(templateFilePath, response,settlement);
} else { } else {
log.error("采购订单号出错!查不到该采购订单!"); log.error("采购订单号出错!查不到该采购订单!");

Loading…
Cancel
Save