| | |
| | | |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO; |
| | | import cn.lihu.jh.module.ecg.service.appointment.AppointmentService; |
| | | import cn.lihu.jh.module.infra.dal.dataobject.config.ConfigDO; |
| | | import cn.lihu.jh.module.infra.service.config.ConfigService; |
| | | import freemarker.template.Configuration; |
| | | import freemarker.template.Template; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | |
| | | import java.io.*; |
| | | import java.time.LocalDate; |
| | | import java.time.Period; |
| | | import java.util.Calendar; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Resource |
| | | private AppointmentService appointmentService; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | private static Configuration configuration = null; |
| | | |
| | |
| | | //捐献表.ftl为要装载的模板 |
| | | t = configuration.getTemplate("知情同意运动试验.ftl"); |
| | | |
| | | String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); |
| | | String name = "知情同意运动试验-" + appointment.getPatName() + "-" + year; |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | String name = "平板运动心电图知情同意书-" + appointment.getPatName() + "-" + time; |
| | | |
| | | //输出文档路径及名称 |
| | | File outFile = new File("D:/" + name + ".doc"); |
| | | ConfigDO configByKey = configService.getConfigByKey("file.upload.path"); |
| | | createPath(configByKey.getValue()); |
| | | File outFile = new File(configByKey.getValue() + name + ".doc"); |
| | | Writer out = null; |
| | | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8")); |
| | | t.process(dataMap, out); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("downloadUrl", "D:/" + name + ".doc"); |
| | | map.put("downloadUrl", "profile/" + name + ".doc"); |
| | | map.put("downloadName", name + ".doc"); |
| | | return map; |
| | | } catch (Exception e) { |
| | |
| | | //捐献表.ftl为要装载的模板 |
| | | t = configuration.getTemplate("食管心脏电生理知情同意书.ftl"); |
| | | |
| | | String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); |
| | | String name = "食管心脏电生理知情同意书-" + appointment.getPatName() + "-" + year; |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | String name = "食管心脏电生理知情同意书-" + appointment.getPatName() + "-" + time; |
| | | |
| | | //输出文档路径及名称 |
| | | File outFile = new File("D:/" + name + ".doc"); |
| | | ConfigDO configByKey = configService.getConfigByKey("file.upload.path"); |
| | | createPath(configByKey.getValue()); |
| | | File outFile = new File(configByKey.getValue() + name + ".doc"); |
| | | Writer out = null; |
| | | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8")); |
| | | t.process(dataMap, out); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("downloadUrl", "D:/" + name + ".doc"); |
| | | map.put("downloadUrl", "profile/" + name + ".doc"); |
| | | map.put("downloadName", name + ".doc"); |
| | | return map; |
| | | } catch (Exception e) { |
| | |
| | | return Period.between(birthdayStr, LocalDate.now()).getYears(); |
| | | } |
| | | |
| | | public void createPath(String uploadPath) { |
| | | // 确保路径以斜杠结尾 |
| | | if (!uploadPath.endsWith("/") && !uploadPath.endsWith("\\")) { |
| | | uploadPath += "/"; |
| | | } |
| | | |
| | | // 创建目录(如果不存在) |
| | | File uploadDir = new File(uploadPath); |
| | | if (!uploadDir.exists()) { |
| | | boolean created = uploadDir.mkdirs(); |
| | | if (created) { |
| | | log.info("创建目录成功: {}", uploadPath); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |