Bladeren bron

优化益寿缘处方生成处方图片逻辑

cgp 1 week geleden
bovenliggende
commit
5ebefae896

+ 5 - 0
fs-service/src/main/java/com/fs/his/param/PrescribeXyImgParam.java

@@ -81,4 +81,9 @@ public class PrescribeXyImgParam {
 
     @Excel(name = "医嘱")
     private String remark;
+
+    /**
+     * 当前处方的订单状态
+     * */
+    private Integer status;
 }

+ 1 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsPrescribeServiceImpl.java

@@ -540,6 +540,7 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
                 throw new IllegalArgumentException(String.format("处方单 %d 对应药品为空!",prescribeId));
             }
             PrescribeXyImgParam o = new PrescribeXyImgParam();
+            o.setStatus(fsStoreOrder.getStatus());
             o.setTotalPrice(fsStoreOrder.getPayPrice());
             o.setTime(f.getCreateTime());
             o.setPrescribeId(f.getPrescribeCode());

+ 120 - 19
fs-service/src/main/java/com/fs/his/service/impl/PrescriptionImageServiceImpl.java

@@ -42,6 +42,10 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
      * 模板图片路径
      */
     private static final String TEMPLATE_PATH = "C:\\fs\\ysy_prescribe.jpg";
+    //官方印章
+    private static final String TEMPLATE_PATH_OFFICIAL = "C:\\fs\\ysy_official.png";
+    //已使用印章
+    private static final String TEMPLATE_PATH_USED = "C:\\fs\\ysy_used.png";
 
     /**
      * 模板图片缓存key
@@ -96,6 +100,12 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
             // 绘制医嘱
             drawAdvice(pen, param, lastY);
 
+            // 叠加官方印章
+            overlayOfficialSeal(pen, param);
+
+            // 叠加已使用使用印章
+            overlayUsedSeal(pen, param);
+
             // 叠加签名图片
             overlaySignatures(pen, param);
 
@@ -170,14 +180,14 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
     private void drawHeaderInfo(Graphics2D pen, PrescribeXyImgParam param) {
         // 处方编号
         if (StringUtils.isNotBlank(param.getPrescribeId())) {
-            pen.drawString(param.getPrescribeId(), 252, 205);
+            pen.drawString(param.getPrescribeId(), 282, 215);
         }
 
         // 时间
         if (param.getTime() != null) {
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
             String timeStr = sdf.format(param.getTime());
-            pen.drawString(timeStr, 948, 205);
+            pen.drawString(timeStr, 1228, 215);
         }
     }
 
@@ -185,27 +195,27 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
      * 绘制患者信息
      */
     private void drawPatientInfo(Graphics2D pen, PrescribeXyImgParam param) {
-        int y = 317;
+        int y = 320;
 
         // 姓名
         if (StringUtils.isNotBlank(param.getPatientName())) {
-            pen.drawString(param.getPatientName(), 177, y);
+            pen.drawString(param.getPatientName(), 217, y);
         }
 
         // 性别
         if (StringUtils.isNotBlank(param.getPatientGender())) {
             String gender = "1".equals(param.getPatientGender()) ? "男" : "女";
-            pen.drawString(gender, 458, y);
+            pen.drawString(gender, 658, y);
         }
 
         // 年龄
         if (StringUtils.isNotBlank(param.getPatientAge())) {
-            pen.drawString(param.getPatientAge(), 679, y);
+            pen.drawString(param.getPatientAge(), 979, y);
         }
 
         // 电话
         if (StringUtils.isNotBlank(param.getTelPhone())) {
-            pen.drawString(param.getTelPhone(), 953, y);
+            pen.drawString(param.getTelPhone(), 1290, y);
         }
     }
 
@@ -214,9 +224,9 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
      */
     private void drawDiagnosis(Graphics2D pen, PrescribeXyImgParam param) {
         if (StringUtils.isNotBlank(param.getDiagnose())) {
-            int x = 133;
-            int y = 548;
-            int maxWidth = 760;
+            int x = 233;
+            int y = 550;
+            int maxWidth = 1350;
             drawMultiLineText(pen, param.getDiagnose(), x, y, maxWidth);
         }
     }
@@ -230,15 +240,15 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
     private void drawDoctorNoAndDoctorTitle(Graphics2D pen, PrescribeXyImgParam param) {
 
         if (StringUtils.isNotBlank(param.getDoctorNo())) {
-            int x = 727;
-            int y = 1905;
+            int x = 890;
+            int y = 1892;
             int maxWidth = 760;
             drawMultiLineText(pen, param.getDoctorNo(), x, y, maxWidth);
         }
 
         if (StringUtils.isNotBlank(param.getDoctorTitle())) {
-            int x = 282;
-            int y = 2079;
+            int x = 302;
+            int y = 2078;
             int maxWidth = 760;
             drawMultiLineText(pen, param.getDoctorTitle(), x, y, maxWidth);
         }
@@ -257,8 +267,8 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
             return 330;
         }
         // ====== 绘制逻辑 ======
-        int x = 133;
-        int y = 680;
+        int x = 105;
+        int y = 720;
         int innerLineSpacing = 40;
         int blankLine = 40;
 
@@ -519,7 +529,7 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
         int y = 1400;
 
         if (StringUtils.isNotBlank(param.getRemark())) {
-            drawMultiLineText(pen, param.getRemark(), 133, y, 500);
+            drawMultiLineText(pen, param.getRemark(), 133, y, 1450);
         }
     }
 
@@ -535,7 +545,7 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
                 BufferedImage doctorSign = downloadSignatureImage(param.getUrl());
                 if (doctorSign != null) {
                     Image scaledSign = doctorSign.getScaledInstance(120, 80, Image.SCALE_SMOOTH);
-                    pen.drawImage(scaledSign, 202, 1842, null);
+                    pen.drawImage(scaledSign, 302, 1842, null);
                 }
             } catch (Exception e) {
                 log.error("加载医师签名失败: {}", param.getUrl(), e);
@@ -548,7 +558,7 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
                 BufferedImage pharmacistSign = downloadSignatureImage(param.getDrugDoctorUrl());
                 if (pharmacistSign != null) {
                     Image scaledSign = pharmacistSign.getScaledInstance(120, 80, Image.SCALE_SMOOTH);
-                    pen.drawImage(scaledSign, 1076, 2028, null);
+                    pen.drawImage(scaledSign, 1400, 2028, null);
                 }
             } catch (Exception e) {
                 log.error("加载药师签名失败: {}", param.getDrugDoctorUrl(), e);
@@ -556,6 +566,97 @@ public class PrescriptionImageServiceImpl implements PrescriptionImageService {
         }
     }
 
+    /**
+     * 叠加官方印章(如:审核通过章)
+     * —— 保持透明,直接绘制
+     */
+    private void overlayOfficialSeal(Graphics2D pen, PrescribeXyImgParam param) {
+        try {
+            BufferedImage seal = getSealImage(TEMPLATE_PATH_OFFICIAL);
+            if (seal != null) {
+                int width = 500;
+                int height = 344;
+                Image scaledSeal = seal.getScaledInstance(width, height, Image.SCALE_SMOOTH);
+                int x = 1315;
+                int y = 1350;
+
+                // 保存原始合成模式
+                Composite originalComposite = pen.getComposite();
+                AlphaComposite transparent = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f);
+                // 设置透明合成模式(如果图片有透明度,这会保留透明度)
+                pen.setComposite(transparent);
+
+                // 绘制印章
+                pen.drawImage(scaledSeal, x, y, null);
+
+                // 恢复原始合成模式
+                pen.setComposite(originalComposite);
+            }
+        } catch (Exception e) {
+            log.error("叠加官方印章失败", e);
+        }
+    }
+
+    /**
+     * 叠加“已使用”印章(如:作废/已发药章)
+     */
+    private void overlayUsedSeal(Graphics2D pen, PrescribeXyImgParam param) {
+
+        if (param.getStatus()!=null && param.getStatus()==3) {
+            //当处方的订单状态为"待收货"时叠加已使用印章
+        try {
+            BufferedImage seal = getSealImage(TEMPLATE_PATH_USED);
+            if (seal != null) {
+                int width = 1045;
+                int height = 577;
+                Image scaledSeal = seal.getScaledInstance(width, height, Image.SCALE_SMOOTH);
+                int x = 125;
+                int y = 1100;
+
+                // 保存原始合成模式
+                Composite originalComposite = pen.getComposite();
+
+                AlphaComposite transparent = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f);
+                // 设置透明合成模式(如果图片有透明度,这会保留透明度)
+                pen.setComposite(transparent);
+
+                // 绘制印章
+                pen.drawImage(scaledSeal, x, y, null);
+
+                // 恢复原始合成模式
+                pen.setComposite(originalComposite);
+            }
+        } catch (Exception e) {
+            log.error("叠加已使用印章失败", e);
+        }
+
+        }
+
+    }
+
+    /**
+     * 获取印章图片(带缓存)
+     */
+    private BufferedImage getSealImage(String path) {
+        if (StringUtils.isBlank(path)) {
+            return null;
+        }
+        return imageCache.get(path, key -> {
+            try {
+                File file = new File(path);
+                if (!file.exists()) {
+                    throw new RuntimeException("印章图片不存在: " + path);
+                }
+                BufferedImage img = ImageIO.read(file);
+                log.debug("印章图片加载成功: {}", path);
+                return img;
+            } catch (Exception e) {
+                log.error("加载印章图片失败: {}", path, e);
+                return null;
+            }
+        });
+    }
+
     /**
      * 下载签名图片(带缓存)
      */