|
|
@@ -12,6 +12,7 @@ import com.xunmei.file.utils.FileDownUtils;
|
|
|
import com.xunmei.file.utils.FileUploadUtils;
|
|
|
import com.xunmei.file.utils.PdfUtil;
|
|
|
import com.xunmei.file.vo.ItextPdfTableVo;
|
|
|
+import com.xunmei.file.vo.PdfFilePathVo;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -57,17 +58,16 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
@Autowired
|
|
|
private HttpServletRequest request;
|
|
|
|
|
|
- private static String getLocalFilePath(String businessType, String fileName) {
|
|
|
+ private static PdfFilePathVo getLocalFilePath(String localFilePath, String businessType, String fileName) {
|
|
|
final String path = File.separator + businessType + File.separator + DateUtil.format(new Date(), "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator);
|
|
|
- File desc = new File(path + fileName);
|
|
|
- log.info("当前上传文件地址:{}", desc.getAbsolutePath());
|
|
|
- if (!desc.exists()) {
|
|
|
- if (!desc.getParentFile().exists()) {
|
|
|
- log.info("创建文件夹:{}", desc.getParentFile());
|
|
|
- desc.getParentFile().mkdirs();
|
|
|
- }
|
|
|
+ final File file = new File(localFilePath + path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
}
|
|
|
- return desc.getPath();
|
|
|
+ PdfFilePathVo pathVo = new PdfFilePathVo();
|
|
|
+ pathVo.setAbsolutePath(localFilePath + path + fileName);
|
|
|
+ pathVo.setRelativePath(path + fileName);
|
|
|
+ return pathVo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -174,23 +174,20 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
|
|
|
@Override
|
|
|
public String generateEduTrainingPdf(Map<String, Object> data) throws Exception {
|
|
|
- String filePath = getLocalFilePath("edu", data.get("fileName").toString());
|
|
|
- log.info("生成教育培训登记簿,当前地址为:{}", filePath);
|
|
|
- final ItextPdfTableVo pdfTableVo = PdfUtil.createTable(filePath, 6, 10);
|
|
|
+ PdfFilePathVo pathVo = getLocalFilePath(localFilePath, "edu", data.get("fileName").toString());
|
|
|
+ log.info("生成教育培训登记簿,当前绝对地址为:{}", pathVo.getAbsolutePath());
|
|
|
+ final ItextPdfTableVo pdfTableVo = PdfUtil.createTable(pathVo.getAbsolutePath(), 6, 10);
|
|
|
final Document document = pdfTableVo.getDocument();
|
|
|
final PdfWriter writer = pdfTableVo.getWriter();
|
|
|
final PdfPTable table = pdfTableVo.getTable();
|
|
|
final BaseFont fs = pdfTableVo.getFs();
|
|
|
final Font tableFont = pdfTableVo.getTableFont();
|
|
|
-
|
|
|
PdfUtil.dealHeader(document, fs, "学 习 教 育 记 录", 24);
|
|
|
-
|
|
|
PdfUtil.dealEduBody(document, table, tableFont, data);
|
|
|
-
|
|
|
document.close();
|
|
|
writer.close();
|
|
|
//此处返回 /statics/edu/xxx.pdf
|
|
|
- return this.prefix + filePath;
|
|
|
+ return this.prefix + pathVo.getRelativePath();
|
|
|
}
|
|
|
|
|
|
}
|