From cfe0b79fbea0fb1d7a5a796e71ada7d3b7812046 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期一, 15 十二月 2025 22:31:33 +0800
Subject: [PATCH] feat: 企业微信发送微信小程序cetd

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java             |   13 ++
 app/permission.js                                                                            |   19 ++++
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/QyWechatServiceImpl.java            |  100 +++++++++++++++++++++++++
 ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java                |    3 
 app/pages/login.vue                                                                          |    6 +
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java      |   19 +++-
 app/utils/auth.js                                                                            |   14 +++
 ruoyi-system/src/main/java/com/ruoyi/system/service/IQyWechatService.java                    |   13 +++
 app/pages/qylogin.vue                                                                        |    6 +
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleMileageStatsController.java |    2 
 ruoyi-admin/src/main/resources/application.yml                                               |    2 
 app/App.vue                                                                                  |    2 
 12 files changed, 185 insertions(+), 14 deletions(-)

diff --git a/app/App.vue b/app/App.vue
index f45cc42..1d029f2 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -28,7 +28,7 @@
         if (token) {
           this.lastToken = token
           this.updateUnreadMessageBadge()
-          this.startMessagePolling()
+          // this.startMessagePolling()
         }
       })
       
diff --git a/app/pages/login.vue b/app/pages/login.vue
index 464d7e4..e30db61 100644
--- a/app/pages/login.vue
+++ b/app/pages/login.vue
@@ -340,6 +340,12 @@
           // 妫�鏌ユ槸鍚︽湁redirect鍙傛暟鎸囧畾璺宠浆椤甸潰
           let redirectUrl = this.getUrlParam("redirect");
           
+          // 濡傛灉娌℃湁redirect鍙傛暟锛屾鏌ユ槸鍚︽湁淇濆瓨鐨勭洰鏍囬〉闈�
+          if (!redirectUrl) {
+            const { getTargetUrl } = require('@/utils/auth')
+            redirectUrl = getTargetUrl()
+          }
+          
           if (redirectUrl) {
             // 瑙g爜redirect鍙傛暟
             redirectUrl = decodeURIComponent(redirectUrl);
diff --git a/app/pages/qylogin.vue b/app/pages/qylogin.vue
index 0d47648..87f219a 100644
--- a/app/pages/qylogin.vue
+++ b/app/pages/qylogin.vue
@@ -223,6 +223,12 @@
         // 妫�鏌ユ槸鍚︽湁redirect鍙傛暟鎸囧畾璺宠浆椤甸潰
         let redirectUrl = this.getUrlParam("redirect");
         
+        // 濡傛灉娌℃湁redirect鍙傛暟锛屾鏌ユ槸鍚︽湁淇濆瓨鐨勭洰鏍囬〉闈�
+        if (!redirectUrl) {
+          const { getTargetUrl } = require('@/utils/auth')
+          redirectUrl = getTargetUrl()
+        }
+        
         if (redirectUrl) {
           // 瑙g爜redirect鍙傛暟
           redirectUrl = decodeURIComponent(redirectUrl);
diff --git a/app/permission.js b/app/permission.js
index fc40fe1..5f79c2f 100644
--- a/app/permission.js
+++ b/app/permission.js
@@ -19,20 +19,39 @@
   return whiteList.indexOf(path) !== -1
 }
 
+// 淇濆瓨鐩爣椤甸潰URL锛岀敤浜庣櫥褰曞悗璺宠浆
+function saveTargetUrl(url) {
+  try {
+    uni.setStorageSync('targetUrl', url)
+  } catch (e) {
+    console.error('淇濆瓨鐩爣URL澶辫触:', e)
+  }
+}
+
 // 椤甸潰璺宠浆楠岃瘉鎷︽埅鍣�
 let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
 list.forEach(item => {
   uni.addInterceptor(item, {
     invoke(to) {
       if (getToken()) {
+        // 宸茬櫥褰�
         if (to.url === loginPage) {
+          // 濡傛灉宸茬粡鐧诲綍杩樿璁块棶鐧诲綍椤碉紝鐩存帴璺宠浆鍒伴椤�
           uni.reLaunch({ url: "/" })
+          return false
         }
         return true
       } else {
+        // 鏈櫥褰�
         if (checkWhite(to.url)) {
+          // 鐧藉悕鍗曢〉闈㈠彲浠ョ洿鎺ヨ闂�
           return true
         }
+        
+        // 淇濆瓨褰撳墠瑕佽闂殑椤甸潰浣滀负鐧诲綍鍚庤烦杞殑鐩爣
+        saveTargetUrl(to.url)
+        
+        // 璺宠浆鍒扮櫥褰曢〉闈�
         uni.reLaunch({ url: loginPage })
         return false
       }
diff --git a/app/utils/auth.js b/app/utils/auth.js
index 9a7cc04..be81c4d 100644
--- a/app/utils/auth.js
+++ b/app/utils/auth.js
@@ -11,3 +11,17 @@
 export function removeToken() {
   return uni.removeStorageSync(TokenKey)
 }
+
+// 鑾峰彇骞舵竻闄ょ洰鏍囬〉闈RL
+export function getTargetUrl() {
+  try {
+    const url = uni.getStorageSync('targetUrl')
+    if (url) {
+      uni.removeStorageSync('targetUrl')
+    }
+    return url
+  } catch (e) {
+    console.error('鑾峰彇鐩爣URL澶辫触:', e)
+    return null
+  }
+}
\ No newline at end of file
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleMileageStatsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleMileageStatsController.java
index 37dd210..c444c62 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleMileageStatsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleMileageStatsController.java
@@ -114,7 +114,7 @@
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
             sdf.setLenient(false); // 涓ユ牸瑙f瀽鏃ユ湡
             Date date = sdf.parse(statDate.trim());
-            logger.info("---> 鎵嬪姩璁$畻杞﹁締閲岀▼姹囨��,杞﹁締ID: {}, 鏃ユ湡: {}", vehicleId, date);
+//            logger.info("---> 鎵嬪姩璁$畻杞﹁締閲岀▼姹囨��,杞﹁締ID: {}, 鏃ユ湡: {}", vehicleId, date);
             VehicleMileageStats stats = vehicleMileageStatsService.calculateAndSaveMileageStats(vehicleId, date);
             // 淇String鍒癉ate杞崲闂锛屾坊鍔犳洿濂界殑閿欒澶勭悊
             if (stats != null) {
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index 4219d2c..105bc73 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -58,7 +58,7 @@
     basename: i18n/messages
   profiles:
     # 鐜 dev|test|prod
-    active: prod
+    active: dev
   # 鏂囦欢涓婁紶
   servlet:
     multipart:
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java b/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java
index a9a1141..e847ee4 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java
@@ -260,7 +260,7 @@
             departure = task.getDepartureAddress();
         }
         DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-        content.append("锛屽嚭鍙戞椂闂达細").append(df.format(dispatchTime));
+        content.append("锛屽嚭鍙戞椂闂�:").append(df.format(dispatchTime));
 
         // 娣诲姞鐩殑鍦颁俊鎭�
         String destination = null;
@@ -271,7 +271,6 @@
         }
         
         if (departure != null || destination != null) {
-            content = new StringBuilder();
             if (departure != null) {
                 content.append("鍑哄彂鍦帮細").append(departure);
             }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IQyWechatService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IQyWechatService.java
index ee6d3dc..a3e6c13 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IQyWechatService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IQyWechatService.java
@@ -19,6 +19,17 @@
     boolean sendNotifyMessage(Long userId, String title, String content, String notifyUrl);
 
     /**
+     * 鍙戦�佷紒涓氬井淇℃秷鎭紝甯﹀皬绋嬪簭璺緞閾炬帴
+     * @param userId
+     * @param title
+     * @param content
+     * @param appId
+     * @param businessUrl 灏忕▼搴忚闂矾寰�
+     * @return
+     */
+    boolean sendNotifyMessage(Long userId, String title, String content, String appId,String businessUrl);
+
+    /**
      * 鍙戦�佷紒涓氬井淇℃枃鏈秷鎭�
      * 
      * @param qyUserId 浼佷笟寰俊鐢ㄦ埛ID
@@ -29,6 +40,8 @@
      */
     boolean sendTextMessage(String qyUserId, String title, String content, String notifyUrl);
 
+    boolean sendTextMessage(String qyUserId, String title, String content, String appId,String businessUrl);
+
     /**
      * 鑾峰彇鐢ㄦ埛鐨勪紒涓氬井淇D
      * 
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java
index 06e3576..9b11a0f 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java
@@ -1,6 +1,7 @@
 package com.ruoyi.system.service.impl;
 
 import com.alibaba.fastjson2.JSON;
+import com.ruoyi.common.config.WechatConfig;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.*;
@@ -49,6 +50,9 @@
     @Autowired
     private IQyWechatService qyWechatService;
 
+
+    @Autowired
+    private WechatConfig wechatConfig;
 
     @Autowired
     private ISysEmergencyTaskService sysEmergencyTaskService;
@@ -348,17 +352,18 @@
            if(emergency==null){
                return false;
            }
-           Long dispatchOrderId = emergency.getLegacyDispatchOrdId();
-          String oldsiteUrl= sysConfigService.selectConfigByKey("oldsite.url");
-          if(oldsiteUrl==null){
-              oldsiteUrl="https://sys.966120.com.cn/m_DispatchOrder.gds?DispatchOrdID=";
-          }
-           String url=oldsiteUrl+dispatchOrderId;
+//           Long dispatchOrderId = emergency.getLegacyDispatchOrdId();
+//          String oldsiteUrl= sysConfigService.selectConfigByKey("oldsite.url");
+//          if(oldsiteUrl==null){
+//              oldsiteUrl="https://sys.966120.com.cn/m_DispatchOrder.gds?DispatchOrdID=";
+//          }
+            String appId=wechatConfig.getAppId();
+           String pathPage="/pagesTask/detail?id="+taskId;
             // 鍙戦�佷紒涓氬井淇℃秷鎭�
             boolean success = qyWechatService.sendNotifyMessage(
                     notifyTask.getUserId(), 
                     notifyTask.getTitle(), 
-                    notifyTask.getContent(),url
+                    notifyTask.getContent(),appId,pathPage
             );
             
             if (success) {
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/QyWechatServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/QyWechatServiceImpl.java
index 8615f04..6d511f2 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/QyWechatServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/QyWechatServiceImpl.java
@@ -65,6 +65,30 @@
         }
     }
 
+    @Override
+    public boolean sendNotifyMessage(Long userId, String title, String content, String appId, String businessUrl) {
+        try {
+            // 妫�鏌ユ湇鍔℃槸鍚﹀惎鐢�
+            if (!isEnabled()) {
+                log.info("浼佷笟寰俊鏈嶅姟鏈惎鐢紝璺宠繃娑堟伅鍙戦��");
+                return false;
+            }
+
+            // 鑾峰彇鐢ㄦ埛鐨勪紒涓氬井淇D
+            String qyUserId = getQyUserIdByUserId(userId);
+            if (StringUtils.isEmpty(qyUserId)) {
+                log.warn("鐢ㄦ埛{}鏈粦瀹氫紒涓氬井淇D锛屾棤娉曞彂閫佹秷鎭�", userId);
+                return false;
+            }
+
+            // 鍙戦�佹枃鏈秷鎭�
+            return sendTextMessage(qyUserId, title, content, appId, businessUrl);
+        } catch (Exception e) {
+            log.error("浼佷笟寰俊娑堟伅鍙戦�佸紓甯革紝userId={}", userId, e);
+            return false;
+        }
+    }
+
     /**
      * 鍙戦�佷紒涓氬井淇℃枃鏈秷鎭�
      */
@@ -101,6 +125,7 @@
             article.setTitle(title);
             article.setDescription(content);
             article.setUrl(notifyUrl);
+
             // 璁剧疆榛樿鍥剧墖URL锛屾偍鍙互鏍规嵁闇�瑕佷慨鏀�
             
 
@@ -141,6 +166,81 @@
         }
     }
 
+    @Override
+    public boolean sendTextMessage(String qyUserId, String title, String content, String appId, String businessUrl) {
+        try {
+            // 妫�鏌ユ湇鍔℃槸鍚﹀惎鐢�
+            if (!isEnabled()) {
+                log.info("浼佷笟寰俊鏈嶅姟鏈惎鐢紝璺宠繃娑堟伅鍙戦��");
+                return false;
+            }
+
+            // 鑾峰彇浼佷笟寰俊閰嶇疆
+            String corpId = configService.selectConfigByKey("qy_wechat.corp_id");
+            String corpSecret = configService.selectConfigByKey("qy_wechat.miniprogram_secret");
+
+            if (StringUtils.isEmpty(corpId) || StringUtils.isEmpty(corpSecret)) {
+                log.error("浼佷笟寰俊閰嶇疆涓嶅畬鏁达紝缂哄皯corpId鎴朿orpSecret");
+                return false;
+            }
+
+            // 鑾峰彇AccessToken
+            String accessToken = qyWechatAccessTokenService.getQyMiniAccessToken(corpId, corpSecret);
+            if (StringUtils.isEmpty(accessToken)) {
+                log.error("鑾峰彇浼佷笟寰俊AccessToken澶辫触");
+                return false;
+            }
+
+            // 鏋勯�犺姹俇RL
+            String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken;
+
+            // 鏋勯�犳枃绔犲璞�
+            QyWechatArticle article = new QyWechatArticle();
+            article.setTitle(title);
+            article.setDescription(content);
+            article.setAppid(appId);
+            article.setPagepath(businessUrl);
+
+            // 璁剧疆榛樿鍥剧墖URL锛屾偍鍙互鏍规嵁闇�瑕佷慨鏀�
+
+
+            // 鏋勯�犺姹傚弬鏁�
+            Map<String, Object> params = new HashMap<>();
+            params.put("touser", qyUserId);
+            params.put("msgtype", "news");
+            params.put("agentid", Integer.parseInt(configService.selectConfigByKey("qywechat.miniprogram.agentid")));
+
+            // 鏋勯�犳枃绔犲垪琛�
+            List<QyWechatArticle> articles = new ArrayList<>();
+            articles.add(article);
+            params.put("news", Collections.singletonMap("articles", articles));
+
+            // 鍙戦�丠TTP POST璇锋眰
+            String response = sendHttpPostRequest(url, params);
+
+            if (StringUtils.isEmpty(response)) {
+                log.error("鍙戦�佷紒涓氬井淇℃秷鎭け璐ワ紝鍝嶅簲涓虹┖");
+                return false;
+            }
+
+            // 瑙f瀽鍝嶅簲缁撴灉
+            QyWechatResponse result = parseResponse(response);
+
+            if (result != null && result.getErrcode() == 0) {
+                log.info("浼佷笟寰俊娑堟伅鍙戦�佹垚鍔燂紝鐢ㄦ埛ID: {}", qyUserId);
+                return true;
+            } else {
+                log.error("浼佷笟寰俊娑堟伅鍙戦�佸け璐ワ紝閿欒鐮�: {}, 閿欒淇℃伅: {}",
+                        result != null ? result.getErrcode() : "unknown",
+                        result != null ? result.getErrmsg() : response);
+                return false;
+            }
+        } catch (Exception e) {
+            log.error("浼佷笟寰俊鏂囨湰娑堟伅鍙戦�佸紓甯革紝qyUserId={}", qyUserId, e);
+            return false;
+        }
+    }
+
     /**
      * 鑾峰彇鐢ㄦ埛鐨勪紒涓氬井淇D
      */
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
index 0644f40..8ea35df 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
@@ -532,6 +532,11 @@
                 }
             }
         }
+        if(updateVO.getAssignees()!=null && !updateVO.getAssignees().isEmpty()){
+           TaskCreateVO.AssigneeInfo assigneeInfo= updateVO.getAssignees().get(0);
+            task.setAssigneeId(assigneeInfo.getUserId());
+            task.setAssigneeName(assigneeInfo.getUserName());
+        }
         // 鐢ㄤ簬璺熻釜鏄惁闇�瑕侀噸鏂板悓姝ワ紙杞﹁締銆佷汉鍛樸�佸湴鍧�銆佹垚浜や环鍙樻洿锛�
         boolean needResync = false;
         int result = sysTaskMapper.updateSysTask(task);
@@ -629,7 +634,7 @@
         if(updateVO.getActualEndTime() != null) {
             task.setActualEndTime(updateVO.getActualEndTime());
         }
-        task.setAssigneeId(updateVO.getAssigneeId());
+//        task.setAssigneeId(updateVO.getAssigneeId());
         task.setUpdateBy(userName);
         task.setUpdateTime(DateUtils.getNowDate());
         task.setRemark(updateVO.getRemark());
@@ -642,7 +647,11 @@
         task.setDepartureLatitude(updateVO.getDepartureLatitude());
         task.setDestinationLongitude(updateVO.getDestinationLongitude());
         task.setDestinationLatitude(updateVO.getDestinationLatitude());
-        
+        if(updateVO.getAssignees()!=null && !updateVO.getAssignees().isEmpty()){
+            TaskCreateVO.AssigneeInfo assigneeInfo= updateVO.getAssignees().get(0);
+            task.setAssigneeId(assigneeInfo.getUserId());
+            task.setAssigneeName(assigneeInfo.getUserName());
+        }
         // 濡傛灉鏇存柊浜嗛儴闂↖D
         if (updateVO.getDeptId() != null) {
             task.setDeptId(updateVO.getDeptId());

--
Gitblit v1.9.1