Ver código fonte

修改迁移

chejianzheng 4 meses atrás
pai
commit
6010254bf2

+ 17 - 14
src/main/java/com/pub/util/MqttUtil.java

@@ -6,6 +6,7 @@ import java.util.*;
 
 import com.wxxcx.index.wxSendMessage;
 import com.wxxcx.user.WxRelatiion;
+import lombok.extern.slf4j.Slf4j;
 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
 import org.eclipse.paho.client.mqttv3.MqttCallback;
 import org.eclipse.paho.client.mqttv3.MqttClient;
@@ -25,6 +26,7 @@ import com.wxxcx.targets.EventListVO;
 import com.wxxcx.user.MiniUserVO;
 import com.wxxcx.ws.PushMsgWebSocket;
 
+@Slf4j
 public class MqttUtil {
     //    private static String HOST = "tcp://119.45.12.173:1883";
     //	测试websocket
@@ -220,6 +222,7 @@ public class MqttUtil {
 
                     // 发送短信
                     if (topic.equals("/das/event") && event.equals("fall_confirmed")) {
+                        System.out.println("mqttutil--有跌倒事件");
                         List<String> openids = new ArrayList<String>();
                         StringBuffer dev_name = new StringBuffer("");
                         // 设备拥有者openid
@@ -228,20 +231,6 @@ public class MqttUtil {
                             openids.add(dev.getUser_openid());
                             dev_name.append(dev.getDev_name());
 
-                            // dev_id dev_info == 拥有者 openId openId ==> userInfo ==> phone oppenId == > wx_relation 微信公众号id
-                            // 这里添加 微信服务号消息推送  String devName, String phoneNo, String fwhOpenId
-                            List<MiniUserVO> users = baseDAO.queryAllByCondition(MiniUserVO.class, "and openid = " + dev.getUser_openid(), null);
-                            String phoneNo = "";
-                            if (users != null && !users.isEmpty()) {
-                                phoneNo = users.get(0).getPhone();
-                            }
-                            List<WxRelatiion> wxRelatiions = baseDAO.queryAllByCondition(WxRelatiion.class, "and openid = " + dev.getUser_openid(), null);
-                            String fwhOpenId = "";
-                            if (wxRelatiions != null && !wxRelatiions.isEmpty()) {
-                                fwhOpenId = wxRelatiions.get(0).getFwhopenid();
-                            }
-                            System.out.println("发送微信公众号信息:devName=" + dev.getDev_name() + ", phoneNo=" + phoneNo + "fwhOpenId=" + fwhOpenId);
-                            wxSendMessage.queryAccessToken(dev.getDev_name(), phoneNo, fwhOpenId);
                         }
                         // 被分享者openid
 //						List<ShareVO> shares = baseDAO.queryAllByCondition(ShareVO.class, " and dev_id ='"+dev_id+"' ", null);
@@ -264,7 +253,21 @@ public class MqttUtil {
                             for (int i = 0; i < users.size(); i++) {
                                 MiniUserVO user = users.get(i);
                                 // 发送跌倒短信
+                                System.out.println("mqttutil--开始发送跌倒消息");
                                 MsgUtil.sendNotifyMsg(user.getPhone(), dev_name.toString());
+                                log.info("mqttutil--sendmsg:phone{}, dev_name:{}", user.getPhone(), dev_name.toString());
+
+                                System.out.println("mqttUtil--消息发完了");
+                                List<WxRelatiion> wxRelatiions = baseDAO.queryAllByConditionNocare(WxRelatiion.class, "and openid = '" + user.getOpenid() + "'", null);
+                                String fwhOpenId = "";
+                                if (wxRelatiions != null && !wxRelatiions.isEmpty()) {
+                                    fwhOpenId = wxRelatiions.get(0).getFwhopenid();
+                                }
+                                System.out.println("mqttutil--当前useropenid=" + user.getOpenid() +", fwhopenId=" + fwhOpenId);
+                                System.out.println("发送微信公众号信息:devName=" + dev_name.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
+//                                log.info("mqttutil--发送微信公众号信息:devName=" + dev.getDev_name() + ", phoneNo=" + phoneNo + "fwhOpenId=" + fwhOpenId);
+                                wxSendMessage.queryAccessToken(dev_name.toString(), user.getPhone(), fwhOpenId);
+                                System.out.println("发送微信公众号消息发完了");
                             }
 
                         }

+ 6 - 0
src/main/java/com/wxxcx/index/wxSendMessage.java

@@ -1,6 +1,8 @@
 package com.wxxcx.index;
 
+import com.alibaba.fastjson.JSON;
 import com.google.gson.Gson;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -16,6 +18,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
+@Slf4j
 public class wxSendMessage {
     private static final String APPID = "wx9b479fa3c2af4f21";
     private static final String SECRET = "426effb7b58f9ba7c5f6dd1062db0074";
@@ -26,6 +29,7 @@ public class wxSendMessage {
         String accessToken = getAccessToken();
         if (accessToken == null) {
             System.out.println("获取 access_token 失败");
+            log.info("获取 access_token 失败");
             return;
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -57,9 +61,11 @@ public class wxSendMessage {
         const2.put("value", "设备运行异常,给用户发送推送");
         data.put("const2", const2);
         System.out.println(data);
+        log.info("mqttutil--sendmessage:{}", JSON.toJSONString(data));
 //        String openid = "oWlo-6iXL0pQeYWZxEpwB8knv6D8";
         boolean result = sendTemplateMessage(accessToken, fwhOpenId, data);
         System.out.println("发送结果: " + (result ? "成功" : "失败"));
+        log.info("发送结果: " + (result ? "成功" : "失败"));
     }
 
     private static String getAccessToken() {