Forráskód Böngészése

上车下次模板消息发送

fllmoyu 4 éve
szülő
commit
3cc2adfa67

+ 2 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/dto/NearbyStationDTO.java

@@ -13,5 +13,7 @@ public class NearbyStationDTO {
 
     private String stationName;
 
+    private String stationId;
+
     private List<NearbyShiftDTO> nearbyShiftDTOList;
 }

+ 41 - 0
common/src/main/java/com/jpsoft/bus/modules/common/utils/WechatMessageUtil.java

@@ -426,6 +426,47 @@ public class WechatMessageUtil {
         return ret;
     }
 
+    /**
+     * 车辆位置提醒
+     * @param openId
+     * @param detail 首行内容
+     * @param appId
+     * @param appSecret
+     * @return
+     */
+    public  boolean sendCarPosition(String openId, String detail, String carNum, String stationName,String reason,String url,String appId, String appSecret) {
+
+
+        String templateId = "nRMewS-cRnxetnf7J4h8gPwMHKud12f3fv36s2eFTQM";
+        JSONObject sendData = new JSONObject();
+
+        JSONObject first = new JSONObject();
+        first.put("value", detail);
+        first.put("color", "#FF0000");
+
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", carNum);
+        keyword1.put("color", "#173177");
+
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", stationName);
+        keyword2.put("color", "#173177");
+
+        JSONObject remark = new JSONObject();
+        remark.put("value", reason);
+        remark.put("color", "#ed1414");
+
+        sendData.put("first", first);
+        sendData.put("keyword1", keyword1);
+        sendData.put("keyword2", keyword2);
+        sendData.put("remark", remark);
+
+
+        boolean ret = sendTemplate(sendData, appId, appSecret, templateId, openId, url);
+
+        return ret;
+    }
+
     /**
      *
      * @param schoolName

+ 1 - 124
web/src/main/java/com/jpsoft/bus/modules/mobile/controller/PassengerApiController.java

@@ -781,6 +781,7 @@ public class PassengerApiController {
                     List<StationInfo> stationInfoList2 = stationInfoService.findByRouteIdAndClassify(routeInfo.getId(),3);
                    // List<StationInfo> stationInfoList1 = stationInfoService.findByRouteId(routeInfo.getId());
 
+                    nearbyStationDTO.setStationId(stationInfo.getId());
                     nearbyStationDTO.setStationName(stationInfo.getName());
 
                     for (int n = 0;n<2;n++){
@@ -880,130 +881,6 @@ public class PassengerApiController {
                     nearbyStationDTOList.add(nearbyStationDTO);
 
 
-
-
-
-
-
-
-
-
-                    /*List<ShiftInfo> shiftInfoList = shiftInfoService.findByRouteIdAndStatus(stationInfo.getRouteId(), "1");
-                    if (shiftInfoList.size() > 0) {
-                            NearbyStationDTO nearbyStationDTO = new NearbyStationDTO();
-                            List<NearbyShiftDTO> nearbyShiftDTOList = new ArrayList<>();
-                            for (ShiftInfo shiftInfo : shiftInfoList) {
-
-
-                                if (!shiftIdList.contains(shiftInfo.getId())) {
-
-                                    //线路
-                                    RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
-                                    List<StationInfo> stationInfos = stationInfoService.findByRouteId(routeInfo.getId());
-
-                                    //当前站
-                                    StationInfo currentStation = stationInfoService.get(shiftInfo.getCurrentStationId());
-
-                                    VehicleInfo vehicleInfo = vehicleInfoService.get(shiftInfo.getVehicleId());
-                                    //起始站
-                                    StationInfo startStation = stationInfoService.get(shiftInfo.getStartStationId());
-                                    //终点站
-                                    StationInfo endStation = stationInfoService.get(shiftInfo.getEndStationId());
-
-                                    //距离
-                                    GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(vehicleInfo.getLatitude()), Double.valueOf(vehicleInfo.getLongitude()));
-                                    GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(latitude), Double.valueOf(longitude));
-
-                                    double meter1 = CommonUtil.getDistanceMeter(source, target, Ellipsoid.Sphere);
-
-                                    //班次当前站下标
-                                    int stationIndex = stationInfos.indexOf(currentStation);
-                                    //行人当前站
-                                    int personStationIndex = stationInfos.indexOf(stationInfo);
-
-                                    //判断顺行还是逆行
-                                    Boolean tmp = false;
-                                    String des = null;
-                                    if (shiftInfo.getStartStationId().equals(stationInfos.get(0).getId())){
-                                        //顺行
-                                        tmp = true;
-                                    }
-                                    if (tmp){
-                                        if (personStationIndex > stationIndex){
-
-                                            int diff = personStationIndex - stationIndex;
-                                            des = diff + "站 "+ (new Double(meter1)).intValue() + "米";
-
-                                        }
-                                    }
-                                    if (!tmp){
-                                        if (personStationIndex < stationIndex){
-                                            int diff = stationIndex - personStationIndex;
-                                            des = diff + "站 "+ (new Double(meter1)).intValue() + "米";
-
-                                        }
-                                    }
-
-                                    if (personStationIndex == stationIndex){
-                                        des = "已到站";
-
-                                    }
-
-                                    if (StringUtils.isNotBlank(des)){
-                                        nearbyStationDTO.setStationName(stationInfo.getName());
-                                       // List<NearbyShiftDTO> nearbyShiftDTOList = new ArrayList<>();
-                                        NearbyShiftDTO nearbyShiftDTO = new NearbyShiftDTO();
-                                        nearbyShiftDTO.setId(shiftInfo.getVehicleId());
-                                        nearbyShiftDTO.setRouteName(routeInfo.getName());
-                                        nearbyShiftDTO.setStartStationName(startStation.getName());
-                                        nearbyShiftDTO.setEndStationName(endStation.getName());
-                                        nearbyShiftDTO.setCurrentStationName(currentStation.getName());
-
-
-                                        nearbyShiftDTO.setDistance((new Double(meter1)).intValue());
-                                        nearbyShiftDTO.setDes(des);
-
-
-                                        nearbyShiftDTOList.add(nearbyShiftDTO);
-                                        nearbyStationDTO.setNearbyShiftDTOList(nearbyShiftDTOList);
-                                        shiftIdList.add(shiftInfo.getId());
-                                    }
-
-
-                                }
-                            }
-                            nearbyStationDTO.setStationName(stationInfo.getName());
-                            nearbyStationDTO.setNearbyShiftDTOList(nearbyShiftDTOList);
-                            if (nearbyShiftDTOList.size()>0){
-                                nearbyStationDTOList.add(nearbyStationDTO);
-                            }
-
-
-                  //      }
-
-                    }else {
-                        NearbyStationDTO nearbyStationDTO = new NearbyStationDTO();
-                        nearbyStationDTO.setStationName(stationInfo.getName());
-                        List<NearbyShiftDTO> nearbyShiftDTOList = new ArrayList<>();
-                        NearbyShiftDTO nearbyShiftDTO = new NearbyShiftDTO();
-
-                        //起始站
-                        List<StationInfo> startStations = stationInfoService.findByRouteIdAndClassify(routeInfo0.getId(),1);
-                        //终点站
-                        List<StationInfo> endStations = stationInfoService.findByRouteIdAndClassify(routeInfo0.getId(),3);
-                        nearbyShiftDTO.setRouteId(routeInfo0.getId());
-                        nearbyShiftDTO.setStartStationName(startStations.get(0).getName());
-                        nearbyShiftDTO.setEndStationName(endStations.get(0).getName());
-
-                        nearbyShiftDTO.setDes("等待发车");
-                        nearbyShiftDTOList.add(nearbyShiftDTO);
-
-                        nearbyStationDTO.setNearbyShiftDTOList(nearbyShiftDTOList);
-
-                        nearbyStationDTOList.add(nearbyStationDTO);
-
-
-                    }*/
                 }
             }
 

+ 19 - 5
web/src/main/java/com/jpsoft/bus/modules/mq/listener/StationRemindListener.java

@@ -1,13 +1,11 @@
 package com.jpsoft.bus.modules.mq.listener;
 
 import com.jpsoft.bus.config.WxConfig;
-import com.jpsoft.bus.modules.bus.entity.RouteInfo;
-import com.jpsoft.bus.modules.bus.entity.ShiftInfo;
-import com.jpsoft.bus.modules.bus.entity.StationInfo;
-import com.jpsoft.bus.modules.bus.entity.StationRemind;
+import com.jpsoft.bus.modules.bus.entity.*;
 import com.jpsoft.bus.modules.bus.service.RouteInfoService;
 import com.jpsoft.bus.modules.bus.service.StationInfoService;
 import com.jpsoft.bus.modules.bus.service.StationRemindService;
+import com.jpsoft.bus.modules.bus.service.VehicleInfoService;
 import com.jpsoft.bus.modules.common.utils.CommonUtil;
 import com.jpsoft.bus.modules.common.utils.WechatMessageUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -30,6 +28,9 @@ public class StationRemindListener {
     @Autowired
     private StationInfoService stationInfoService;
 
+    @Autowired
+    private VehicleInfoService vehicleInfoService;
+
     @Autowired
     private StationRemindService stationRemindService;
 
@@ -55,6 +56,11 @@ public class StationRemindListener {
             StationInfo startStation = stationInfoService.get(shiftInfo.getStartStationId());
             StationInfo endStation = stationInfoService.get(shiftInfo.getEndStationId());
 
+            VehicleInfo vehicleInfo = vehicleInfoService.get(shiftInfo.getVehicleId());
+
+            //当前车辆所在站点
+            StationInfo stationInfo = stationInfoService.get(shiftInfo.getCurrentStationId());
+
             for (StationRemind stationRemind : stationRemindList) {
                 try {
                     String remindStr = "上车刷脸听到“识别成功”通行,入座扫码手机购票。";
@@ -69,6 +75,12 @@ public class StationRemindListener {
                         }
                     }
 
+                    String detail = "上车提醒";
+                    if (stationRemind.getRemindType() == 2){
+                        detail = "下次提醒";
+                    }
+
+
                     StationInfo remindStation = stationInfoService.get(stationRemind.getRemindStationId());
                     StationInfo advanceStation = stationInfoService.get(stationRemind.getAdvanceStationId());
 
@@ -94,7 +106,9 @@ public class StationRemindListener {
 
                     sendData.put("thing3", thing3);
 
-                    wechatMessageUtil.sendSubscribeTemplate(wxConfig.getAppId(), wxConfig.getAppSecret(), templateId, stationRemind.getOpenId(), sendData, "");
+                 //   wechatMessageUtil.sendSubscribeTemplate(wxConfig.getAppId(), wxConfig.getAppSecret(), templateId, stationRemind.getOpenId(), sendData, "");
+
+                    wechatMessageUtil.sendCarPosition(stationRemind.getOpenId(),detail,vehicleInfo.getLicensePlateNumber(),stationInfo.getName(),remindStr,wxConfig.getPortalUrl()+"/pages/buytickets/selectSite?id="+shiftInfo.getVehicleId(),wxConfig.getAppId(), wxConfig.getAppSecret());
 
                     stationRemind.setDelFlag(true);
                     stationRemind.setUpdateTime(new Date());

+ 1 - 1
web/src/main/resources/application-test.yml

@@ -50,7 +50,7 @@ wx:
     refreshOAuth2TokenUrl: "https://api.weixin.qq.com/sns/oauth2/refresh_token"
     createQrCodeUrl: "https://api.weixin.qq.com/cgi-bin/qrcode/create"
     showQrCodeUrl: "https://mp.weixin.qq.com/cgi-bin/showqrcode"
-    portalUrl: http://xpgj.xiaoxinda.com/test/business/#/
+    portalUrl: http://xpgj.xiaoxinda.com/jp-car/#
 
   jpsoft:
     appId: wx907e84ad32e6e142