Jelajahi Sumber

Merge remote-tracking branch 'origin/ScrmStores' into ScrmStores

lmx 4 hari lalu
induk
melakukan
7b127beb55

+ 21 - 0
fs-common/src/main/java/com/fs/common/utils/AbsolutePosition.java

@@ -0,0 +1,21 @@
+package com.fs.common.utils;
+
+import net.coobird.thumbnailator.geometry.Position;
+
+import java.awt.*;
+
+public class AbsolutePosition implements Position {
+    private final int x;
+    private final int y;
+
+    public AbsolutePosition(int x, int y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    @Override
+    public Point calculate(int enclosingWidth, int enclosingHeight, int width, int height, int insetLeft, int insetRight, int insetTop, int insetBottom) {
+        // 直接返回指定的坐标点,作为签名图片左上角的位置
+        return new Point(this.x, this.y);
+    }
+}

+ 62 - 3
fs-common/src/main/java/com/fs/common/utils/ThumbnailatorWatermark.java

@@ -4,6 +4,7 @@ import net.coobird.thumbnailator.Thumbnails;
 import net.coobird.thumbnailator.geometry.Positions;
 
 import javax.imageio.ImageIO;
+import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -15,14 +16,14 @@ import java.net.URL;
 public class ThumbnailatorWatermark {
 
     /**
-     * 对网络图片添加水印并返回字节数组
+     * 对处方图片添加水印并返回字节数组
      *
-     * @param imageUrl           网络图片的URL
+     * @param imageUrl           处方图片的URL
      * @param watermarkImageUrl 本地水印图片路径
      * @return 添加水印后的图片字节数组
      * @throws IOException
      */
-    public static byte[] addWatermarkToNetworkImage(String imageUrl, String watermarkImageUrl) throws IOException {
+    public static byte[] addWatermarkToNetworkImage(String imageUrl, String watermarkImageUrl,String doctorName) throws IOException {
         try {
             // 读取原图片
             URL url = new URL(imageUrl);
@@ -33,11 +34,19 @@ public class ThumbnailatorWatermark {
             InputStream watermarkInputStream = watermarkURL.openStream();
             BufferedImage watermarkImage = ImageIO.read(watermarkInputStream);
 
+            // 创建签名图片
+            BufferedImage signatureImage = createTextImageWithBorder(doctorName, Color.RED, 36,2);
+
             // 使用Thumbnailator处理并输出到字节数组
             ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
             Thumbnails.of(inputStream)
                     .scale(1)
                     .watermark(Positions.TOP_RIGHT, watermarkImage, 0.5f)
+                    .watermark(
+                            new AbsolutePosition(860, 1340), // 使用自定义坐标位置
+                            signatureImage,
+                            0.7f // 透明度
+                    )
                     .outputQuality(0.9)
                     .outputFormat("jpg")
                     .toOutputStream(outputStream);
@@ -51,4 +60,54 @@ public class ThumbnailatorWatermark {
         }
     }
 
+    private static BufferedImage createTextImageWithBorder(String text, Color color, int fontSize, int borderWidth) {
+        // 创建临时Graphics以计算文字尺寸
+        BufferedImage tempImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
+        Graphics2D g = tempImage.createGraphics();
+        Font font = new Font("微软雅黑", Font.PLAIN, fontSize);
+        g.setFont(font);
+        FontMetrics metrics = g.getFontMetrics();
+
+        // 计算文字宽度和高度
+        int textWidth = metrics.stringWidth(text);
+        int textHeight = metrics.getHeight();
+        g.dispose();
+
+        // 添加边框和内边距
+        int padding = 5; // 文字与边框之间的内边距
+        int totalWidth = textWidth + 2 * (borderWidth + padding);
+        int totalHeight = textHeight + 2 * (borderWidth + padding);
+
+        // 创建正式的文字图片 - 使用透明背景
+        BufferedImage textImage = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_ARGB);
+        Graphics2D g2d = textImage.createGraphics();
+
+        // 设置抗锯齿
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+        // 绘制圆角矩形边框
+        g2d.setColor(color);
+        g2d.setStroke(new BasicStroke(borderWidth)); // 设置边框粗细
+        g2d.drawRoundRect(
+                borderWidth/2,
+                borderWidth/2,
+                totalWidth - borderWidth,
+                totalHeight - borderWidth,
+                10, 10 // 圆角半径
+        );
+
+        // 设置字体和颜色
+        g2d.setFont(font);
+        g2d.setColor(color);
+
+        // 绘制文字 - 位置居中
+        int textX = (totalWidth - textWidth) / 2;
+        int textY = (totalHeight - textHeight) / 2 + metrics.getAscent();
+        g2d.drawString(text, textX, textY);
+
+        g2d.dispose();
+        return textImage;
+    }
+
 }

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

@@ -819,7 +819,7 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
         try {
             // 处方添加水印
             CloudStorageService storage = OSSFactory.build();
-            String url = storage.uploadSuffix(ThumbnailatorWatermark.addWatermarkToNetworkImage(prescribe.getDstFilePath(),configService.selectConfigByKey("his.prescription.url") ), ".jpg");
+            String url = storage.uploadSuffix(ThumbnailatorWatermark.addWatermarkToNetworkImage(prescribe.getDstFilePath(),configService.selectConfigByKey("his.prescription.url"),doctor.getDoctorName()), ".jpg");
             prescribe.setDstFilePath(url);
         } catch (IOException e) {
         }

+ 8 - 5
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreCartScrmMapper.java

@@ -106,12 +106,15 @@ public interface FsStoreCartScrmMapper
     Integer selectFsStoreCartCountByUserId(long userId);
     @Select({"<script> " +
             "select ifnull(sum(c.cart_num),0) from fs_store_cart_scrm c  " +
-            "where c.is_pay=0 and c.is_del=0 and c.is_buy=0 " +
-            "<if test = 'maps.userId != null     '> " +
-            "and c.user_id =#{maps.userId} " +
+            "inner join fs_store_product_scrm p on p.product_id = c.product_id " +
+            "inner join fs_store_product_attr_value_scrm v on v.id = c.product_attr_value_id " +
+            "left join fs_store_scrm s on v.store_id = s.store_id " +
+            "where c.is_pay = 0 and c.is_del = 0 and c.is_buy = 0 and p.is_show = 1 and p.is_del = 0 " +
+            "<if test='maps.userId != null'> " +
+            "and c.user_id = #{maps.userId} " +
             "</if>" +
-            "<if test = 'maps.productId != null    '> " +
-            "and c.product_id =#{maps.productId} " +
+            "<if test='maps.productId != null'> " +
+            "and c.product_id = #{maps.productId} " +
             "</if>" +
             "</script>"})
     Integer selectFsStoreCartCount(@Param("maps") FsStoreCartCountParam param);

+ 6 - 2
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -3908,6 +3908,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         String cartIds = redisCache.getCacheObject("orderKey:" + param.getOrderKey());
         Integer totalNum = 0;
         BigDecimal integral = BigDecimal.ZERO;
+        String storeId = null;
         if (cartIds != null) {
             //获取购物车列表
             List<FsStoreCartScrmQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
@@ -3925,6 +3926,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 if (cart.getCateId() != null && cart.getCateId().equals(176L)) {
                     meiruCount++;
                 }
+                if(StringUtils.isNotEmpty(cart.getStoreId())){
+                    storeId=cart.getStoreId();
+                }
             }
             //生成分布式唯一值
             String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
@@ -3958,8 +3962,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             storeOrder.setTotalPrice(dto.getTotalPrice());
             storeOrder.setTotalPostage(dto.getPayPostage());
 
-            if (param.getStoreId() != null) {
-                storeOrder.setStoreId(param.getStoreId());
+            if (storeId != null) {
+                storeOrder.setStoreId(Long.valueOf(storeId));
             }
 
             //优惠券处理