package com.glxp.api.service.inv; import cn.hutool.core.thread.ThreadUtil; import com.glxp.api.dao.inv.InvInnerOrderPdfTempDao; import com.glxp.api.entity.inv.InvInnerOrderPdfTempEntity; import com.glxp.api.res.inv.InnerOrderPrintResponse; import com.glxp.api.util.JasperUtils; import net.sf.jasperreports.engine.JRException; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class JaspaperService { @Value("${file_path}") private String dirPath; @Resource private InvInnerOrderPdfTempDao innerOrderPdfTempDao; @Async public void printPdfLocal(List> splits, List stockPrintTempEntities, String resource) { ThreadUtil.execAsync(() -> { for (int i = 0; i < stockPrintTempEntities.size(); i++) { InvInnerOrderPdfTempEntity stockPrintTempEntity = stockPrintTempEntities.get(i); Map data = new HashMap(); data.put("data", splits.get(i)); try { JasperUtils.jasperReportToFile(stockPrintTempEntity.getFilePath(), data, resource); stockPrintTempEntity.setStatus(1); } catch (IOException e) { stockPrintTempEntity.setStatus(2); e.printStackTrace(); } catch (JRException e) { stockPrintTempEntity.setStatus(2); e.printStackTrace(); } innerOrderPdfTempDao.updateById(stockPrintTempEntity); } }); } }