Browse Source

1.短信切换正式信息
2.上传文件代码优化,修复水印消失的问题,自动改颜色
3.文章列表代码bug修复

fangzhen 4 months ago
parent
commit
6dc6fa94dd

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java

@@ -125,7 +125,7 @@ public class CaptchaController {
         }
         }
 
 
         //2.发送验证码
         //2.发送验证码
-        SendSms.sendMsg("次元时代App", "SMS_474845159", phoneNumber, String.valueOf(code));
+        SendSms.sendMsg("次元时代App", "SMS_474620142", phoneNumber, String.valueOf(code));
         //3.存入redis
         //3.存入redis
 
 
         redisCache.setCacheObject(verifyKey, code, 120, TimeUnit.MINUTES);
         redisCache.setCacheObject(verifyKey, code, 120, TimeUnit.MINUTES);

+ 50 - 2
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/ImageUtils.java

@@ -103,7 +103,7 @@ public class ImageUtils {
         // 根据图片大小调整字体大小
         // 根据图片大小调整字体大小
         int fontSize = Math.max(width, height) / 40; // 字体大小为图片较大边长的 1/20
         int fontSize = Math.max(width, height) / 40; // 字体大小为图片较大边长的 1/20
         g2d.setFont(new Font("SimHei", Font.BOLD, fontSize));
         g2d.setFont(new Font("SimHei", Font.BOLD, fontSize));
-        g2d.setColor(new Color(255, 255, 255, 128)); // 白色半透明
+//        g2d.setColor(new Color(255, 255, 255, 128)); // 白色半透明
 
 
         // 计算水印文本宽高
         // 计算水印文本宽高
         FontMetrics fontMetrics = g2d.getFontMetrics();
         FontMetrics fontMetrics = g2d.getFontMetrics();
@@ -121,12 +121,60 @@ public class ImageUtils {
         int y1 = height - textHeight - padding; // 第一行垂直位置
         int y1 = height - textHeight - padding; // 第一行垂直位置
         int y2 = height - padding; // 第二行垂直位置
         int y2 = height - padding; // 第二行垂直位置
 
 
+        // 分析水印区域的背景颜色(取样水印区域的平均颜色)
+        Color averageColor = getAverageColor(image, x1, y1 - textHeight, textWidth1, textHeight + (y2 - y1));
+
+        // 判断背景颜色是否浅色或深色
+        Color watermarkColor = isLightColor(averageColor) ? new Color(0, 0, 0, 180) : new Color(255, 255, 255, 128);
+
+        // 设置水印颜色
+        g2d.setColor(watermarkColor);
+
         // 绘制两行水印
         // 绘制两行水印
         g2d.drawString(watermarkText1, x1, y1);
         g2d.drawString(watermarkText1, x1, y1);
         g2d.drawString(watermarkText2, x2, y2);
         g2d.drawString(watermarkText2, x2, y2);
         g2d.dispose();
         g2d.dispose();
 
 
         // 保存处理后的图片
         // 保存处理后的图片
-        ImageIO.write(image, "jpg", destFile);
+//        ImageIO.write(image, "jpg", destFile);
+        String format = sourceFile.getName().substring(sourceFile.getName().lastIndexOf(".") + 1);
+        ImageIO.write(image, format, destFile);
+    }
+
+
+    /**
+     * 判断颜色是否为浅色
+     *
+     * @param color 颜色
+     * @return true 表示浅色,false 表示深色
+     */
+    private static boolean isLightColor(Color color) {
+        // 使用加权公式计算亮度
+        double brightness = (color.getRed() * 0.299 + color.getGreen() * 0.587 + color.getBlue() * 0.114);
+        return brightness > 128; // 亮度大于128为浅色
+    }
+
+    /**
+     * 获取指定区域的平均颜色
+     *
+     * @param image 图片
+     * @param x 起始横坐标
+     * @param y 起始纵坐标
+     * @param width 区域宽度
+     * @param height 区域高度
+     * @return 平均颜色
+     */
+    private static Color getAverageColor(BufferedImage image, int x, int y, int width, int height) {
+        int r = 0, g = 0, b = 0, count = 0;
+        for (int i = x; i < x + width && i < image.getWidth(); i++) {
+            for (int j = y; j < y + height && j < image.getHeight(); j++) {
+                Color pixelColor = new Color(image.getRGB(i, j));
+                r += pixelColor.getRed();
+                g += pixelColor.getGreen();
+                b += pixelColor.getBlue();
+                count++;
+            }
+        }
+        return new Color(r / count, g / count, b / count);
     }
     }
 }
 }

+ 14 - 11
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -161,20 +161,23 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         int offset = (pageNum - 1) * pageSize;
         int offset = (pageNum - 1) * pageSize;
         communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType);
         communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType);
 
 
-        //剔除是否有合集文章
-        List<Long> ids = communityArticleVos.stream().map(item -> item.getId()).collect(Collectors.toList());
-        List<CommunityCollectionArticle> collections = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
-                .in("article_id", ids)
-                .and((wrapper) -> {
-                    wrapper.ne("is_delete", true).or().isNull("is_delete");
-                }));
         List<CommunityArticleVo> articleVos_copy = new ArrayList<>(communityArticleVos);
         List<CommunityArticleVo> articleVos_copy = new ArrayList<>(communityArticleVos);
         if (noCollection != null){
         if (noCollection != null){
             if (noCollection == 1) {
             if (noCollection == 1) {
-                for (CommunityArticleVo communityArticleVo : articleVos_copy) {
-                    for (CommunityCollectionArticle collection : collections) {
-                        if(collection.getArticleId().equals(communityArticleVo.getId())){
-                            communityArticleVos.remove(communityArticleVo);
+                //剔除是否有合集文章
+                List<Long> ids = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
+                if (!ids.isEmpty()) {
+                    List<CommunityCollectionArticle> collections = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
+                            .in("article_id", ids)
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true).or().isNull("is_delete");
+                            }));
+
+                    for (CommunityArticleVo communityArticleVo : articleVos_copy) {
+                        for (CommunityCollectionArticle collection : collections) {
+                            if(collection.getArticleId().equals(communityArticleVo.getId())){
+                                communityArticleVos.remove(communityArticleVo);
+                            }
                         }
                         }
                     }
                     }
                 }
                 }

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/util/SendSms.java

@@ -42,7 +42,7 @@ public class SendSms {
         // Parameter settings for API request
         // Parameter settings for API request
         SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
         SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
                 .signName(StringUtils.nvl(signName, "社区功能"))
                 .signName(StringUtils.nvl(signName, "社区功能"))
-                .templateCode(StringUtils.nvl(templateCode, "SMS_474645121"))
+                .templateCode(StringUtils.nvl(templateCode, "SMS_474620142"))
                 .phoneNumbers(StringUtils.nvl(phoneNumbers, "13358039598"))
                 .phoneNumbers(StringUtils.nvl(phoneNumbers, "13358039598"))
                 .templateParam(objCode.toJSONString())
                 .templateParam(objCode.toJSONString())
                 // Request-level configuration rewrite, can set Http request parameters, etc.
                 // Request-level configuration rewrite, can set Http request parameters, etc.