You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
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<List<InnerOrderPrintResponse>> splits, List<InvInnerOrderPdfTempEntity> stockPrintTempEntities, String resource) {
|
|
|
|
ThreadUtil.execAsync(() -> {
|
|
for (int i = 0; i < stockPrintTempEntities.size(); i++) {
|
|
InvInnerOrderPdfTempEntity stockPrintTempEntity = stockPrintTempEntities.get(i);
|
|
Map<String, Object> data = new HashMap<String, Object>();
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|