From b3176719f4e73bd5ea67ac6b6835d74fd607e102 Mon Sep 17 00:00:00 2001
From: yaozc2021 <yaozc@yhzhg.cn>
Date: Mon, 21 Apr 2025 03:00:11 +0000
Subject: [PATCH] Merge branch 'wcd-2411-update' of http://192.168.1.110:5678/r/pms-upgrade into wcd

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java |   63 +++++++++++++++++++++++++++++--
 1 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
index 63e2e7c..04f5fcb 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
@@ -4,6 +4,7 @@
 import lombok.RequiredArgsConstructor;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.bean.message.WxCpMessage;
 import me.chanjar.weixin.cp.bean.oa.WxCpCheckinData;
 import me.zhengjie.modules.attendance.domain.*;
 import me.zhengjie.modules.attendance.repository.*;
@@ -262,10 +263,10 @@
      */
     @Transactional(rollbackFor = Exception.class)
     public void getWeComAttendanceListOfNight(String attendDate, List attUser) throws Exception {
-        // 获取企业微信Token
-        wxCpService.getAccessToken();
-
         try {
+            // 获取企业微信Token
+            wxCpService.getAccessToken();
+
             // 获取参数日期类
             Calendar calAttendDate = Calendar.getInstance();
             // 日期格式化
@@ -375,6 +376,7 @@
 
     /**
      * 中午12点30或凌晨02:30执行定时任务
+     *
      * @throws Exception
      */
     public void getWeComAttendanceListOfNoonOrNight(String attendDate, List attUser) throws Exception {
@@ -421,7 +423,6 @@
         }
         return attendance;
     }
-
 
     /**
      * 请假优先于出差优先于外出
@@ -822,4 +823,58 @@
         }
         return null;
     }
+
+    /**
+     * 发送企微应用消息
+     *
+     * @param userWeComIdList 接收消息用户企微ID
+     * @param content         消息内容
+     * @param type            消息类型
+     */
+    public void sendNotice(List<String> userWeComIdList, String title, String content, String type) {
+        if (userWeComIdList.size() > 0) {
+            try {
+                // 获取企业微信Token
+                wxCpService.getAccessToken();
+
+                // 编辑消息
+                WxCpMessage wxCpMessage = new WxCpMessage();
+                wxCpMessage.setToUser(userWeComIdList.stream().collect(Collectors.joining("|")));
+                if (type.equals(Constant.WECOM_MESSAGE_TYPE_TEXT)) {
+                    wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_TEXT);
+                    wxCpMessage.setContent(content);
+                } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_IMAGE)) {
+                    wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_IMAGE);
+                    wxCpMessage.setMediaId(content);
+                } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_VOICE)) {
+                    wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_VOICE);
+                    wxCpMessage.setMediaId(content);
+                } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_VIDEO)) {
+                    wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_VIDEO);
+                    wxCpMessage.setMediaId(content);
+                    wxCpMessage.setTitle(title);
+                } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_FILE)) {
+                    wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_FILE);
+                    wxCpMessage.setMediaId(content);
+                } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_TEXTCARD)) {
+                    wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
+                    wxCpMessage.setTitle(title);
+                    wxCpMessage.setDescription(content);
+                    wxCpMessage.setUrl(Constant.WECOM_MESSAGE_URL);
+                    wxCpMessage.setBtnTxt(Constant.WECOM_MESSAGE_BTNTXT);
+                } else {
+                    wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_TEXT);
+                    wxCpMessage.setContent(content);
+                }
+                wxCpMessage.setSafe("0");
+                wxCpMessage.setEnableDuplicateCheck(false);
+                wxCpMessage.setDuplicateCheckInterval(600);
+
+                // 发送消息
+                wxCpService.getMessageService().send(wxCpMessage);
+            } catch (WxErrorException wxErrorException) {
+                wxErrorException.printStackTrace();
+            }
+        }
+    }
 }

--
Gitblit v1.9.3