소스 검색

增加到站提醒

zhengqiang 4 년 전
부모
커밋
761a7a2279
22개의 변경된 파일1126개의 추가작업 그리고 31개의 파일을 삭제
  1. 6 2
      common/src/main/java/com/jpsoft/bus/modules/bus/callback/GpsDataCallbackImpl.java
  2. 4 0
      common/src/main/java/com/jpsoft/bus/modules/bus/dao/PassengerInfoDAO.java
  3. 20 0
      common/src/main/java/com/jpsoft/bus/modules/bus/dao/StationRemindDAO.java
  4. 1 1
      common/src/main/java/com/jpsoft/bus/modules/bus/entity/ShiftInfo.java
  5. 89 0
      common/src/main/java/com/jpsoft/bus/modules/bus/entity/StationRemind.java
  6. 4 0
      common/src/main/java/com/jpsoft/bus/modules/bus/service/PassengerInfoService.java
  7. 19 0
      common/src/main/java/com/jpsoft/bus/modules/bus/service/StationRemindService.java
  8. 10 0
      common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/PassengerInfoServiceImpl.java
  9. 80 0
      common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/StationRemindServiceImpl.java
  10. 142 0
      common/src/main/java/com/jpsoft/bus/modules/common/utils/SnowflakeIdWorker.java
  11. 75 11
      common/src/main/java/com/jpsoft/bus/modules/common/utils/WechatMessageUtil.java
  12. 25 1
      common/src/main/resources/mapper/bus/PassengerInfo.xml
  13. 136 0
      common/src/main/resources/mapper/bus/StationRemind.xml
  14. 3 1
      gps/src/main/java/com/jpsoft/gps/handler/ProcessHandler.java
  15. 2 1
      web/src/main/java/com/jpsoft/bus/config/RabbitmqConfig.java
  16. 2 2
      web/src/main/java/com/jpsoft/bus/config/WebMvcConfig.java
  17. 1 2
      web/src/main/java/com/jpsoft/bus/modules/mobile/controller/PassengerApiController.java
  18. 373 0
      web/src/main/java/com/jpsoft/bus/modules/mobile/controller/StationRemindApiController.java
  19. 123 0
      web/src/main/java/com/jpsoft/bus/modules/mq/listener/StationRemindListener.java
  20. 9 9
      web/src/main/resources/application-dev.yml
  21. 1 1
      web/src/main/resources/application-test.yml
  22. 1 0
      web/src/main/resources/application.yml

+ 6 - 2
common/src/main/java/com/jpsoft/bus/modules/bus/callback/GpsDataCallbackImpl.java

@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.joda.time.DateTime;
 import org.joda.time.Minutes;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.stereotype.Component;
@@ -62,6 +63,9 @@ public class GpsDataCallbackImpl implements GpsDataCallback {
     @Autowired
     private GpsParamConfig gpsParamConfig;
 
+    @Autowired
+    private RabbitTemplate rabbitTemplate;
+
     @Override
     public void receive(String deviceNo, String longitude, String latitude) {
         log.warn("保存实时数据:{},{},{}", deviceNo, longitude, latitude);
@@ -139,13 +143,13 @@ public class GpsDataCallbackImpl implements GpsDataCallback {
 
                         StationInfo currentStation = stationInfoService.get(stationId);
 
-
-
                         //站点发生变化时
                         if (!shiftInfo.getCurrentStationId().equals(stationId)){
                             shiftInfo.setCurrentStationId(stationId);
                             shiftInfoService.update(shiftInfo);
 
+                            rabbitTemplate.convertAndSend("stationRemindQueue", shiftInfo);
+
                             //当前站点
                           //  StationInfo currentStation = stationInfoService.get(stationId);
                             //此线路的所有站点

+ 4 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/dao/PassengerInfoDAO.java

@@ -19,4 +19,8 @@ public interface PassengerInfoDAO {
     List<PassengerInfo> findByPersonIdShiftIdStatus(Long personId, String shiftId, String status);
 
     List<PassengerInfo> findByShiftStatusPayStatusNotTicketDown(String shiftId, String status, String payStatus,String ticketDownStationId);
+
+    List<PassengerInfo> findByOpenIdAndStatus(String openId, String status,String payStatus);
+
+	List<PassengerInfo> findByOpenIdAndVehicleShiftId(String openId, String vehicleShiftId, String status, String payStatus);
 }

+ 20 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/dao/StationRemindDAO.java

@@ -0,0 +1,20 @@
+package com.jpsoft.bus.modules.bus.dao;
+
+import java.util.List;
+import org.springframework.stereotype.Repository;
+import com.jpsoft.bus.modules.bus.entity.StationRemind;
+import java.util.Map;
+import com.jpsoft.bus.modules.common.dto.Sort;
+
+@Repository
+public interface StationRemindDAO {
+	int insert(StationRemind entity);
+	int update(StationRemind entity);
+	int exist(String id);
+	StationRemind get(Long id);
+	int delete(String id);
+	List<StationRemind> list();
+	List<StationRemind> search(Map<String, Object> searchParams, List<Sort> sortList);
+    List<StationRemind> findByAdvanceStationId(String currentStationId);
+	StationRemind findByOpenIdAndVehicleShiftId(String openId, String vehicleShiftId);
+}

+ 1 - 1
common/src/main/java/com/jpsoft/bus/modules/bus/entity/ShiftInfo.java

@@ -16,7 +16,7 @@ import lombok.Data;
  */
 @Data
 @ApiModel(value = "bus_shift_info的实体类")
-public class ShiftInfo {
+public class ShiftInfo implements Serializable {
     @ApiModelProperty(value = "车辆班次编号")
     private String id;
     @ApiModelProperty(value = "司机")

+ 89 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/entity/StationRemind.java

@@ -0,0 +1,89 @@
+package com.jpsoft.bus.modules.bus.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.math.BigDecimal;
+
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+ * 描述:bus_station_remind的实体类
+ */
+@Data
+@ApiModel(value = "bus_station_remind的实体类")
+public class StationRemind {
+    /**
+     * 雪花主键
+     */
+    @ApiModelProperty(value = "雪花主键")
+    private Long id;
+    /**
+     * 起始站点编号
+     */
+    @ApiModelProperty(value = "起始站点编号")
+    private String startStationId;
+    /**
+     * 提醒站点编号
+     */
+    @ApiModelProperty(value = "提醒站点编号")
+    private String remindStationId;
+    /**
+     * 提前多少站通知
+     */
+    @ApiModelProperty(value = "提前多少站通知")
+    private Integer stopInAdvance;
+    /**
+     * 提前通知编号
+     */
+    @ApiModelProperty(value = "提前通知编号")
+    private String advanceStationId;
+    /**
+     * 用户微信openid
+     */
+    @ApiModelProperty(value = "用户微信openid")
+    private String openId;
+    /**
+     * 1-上车提醒,2-下车提醒
+     */
+    @ApiModelProperty(value = "1-上车提醒,2-下车提醒")
+    private Integer remindType;
+    /**
+     * 班次编号(下车提醒用)
+     */
+    @ApiModelProperty(value = "班次编号(下车提醒用)")
+    private String vehicleShiftId;
+    /**
+     * 创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+    /**
+     * 创建时间
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 更新人
+     */
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+    /**
+     * 更新时间
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+    /**
+     * 是否删除
+     */
+    @ApiModelProperty(value = "是否删除")
+    private Boolean delFlag;
+}

+ 4 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/PassengerInfoService.java

@@ -33,4 +33,8 @@ public interface PassengerInfoService {
 	MergeOrderDTO createOrder(VehicleInfo vehicleInfo, ShiftInfo shiftInfo, String openId, String mergeOrderId, String passengerIds, String ticketUpStationId, String ticketDownStationId, String ticketTypes, String goodsTicket, String totalFee) throws Exception;
 
 	void updatePassengerOrder(OrderInfo orderInfo, String ticketUpStationId, String ticketDownStationId, String ticketType, String goodsTicket, String totalFee);
+
+    List<PassengerInfo> findByOpenIdAndStatus(String openId, String status,String payStatus);
+
+	List<PassengerInfo> findByOpenIdAndVehicleShiftId(String openId, String vehicleShiftId, String status,String payStatus);
 }

+ 19 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/StationRemindService.java

@@ -0,0 +1,19 @@
+package com.jpsoft.bus.modules.bus.service;
+
+import java.util.List;
+import java.util.Map;
+import com.jpsoft.bus.modules.bus.entity.StationRemind;
+import com.github.pagehelper.Page;
+import com.jpsoft.bus.modules.common.dto.Sort;
+
+public interface StationRemindService {
+	StationRemind get(Long id);
+	boolean exist(String id);
+	int insert(StationRemind model);
+	int update(StationRemind model);
+	int delete(String id);
+	List<StationRemind> list();
+	Page<StationRemind> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
+    List<StationRemind> findByAdvanceStationId(String currentStationId);
+    StationRemind findByOpenIdAndVehicleShiftId(String openId, String vehicleShiftId);
+}

+ 10 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/PassengerInfoServiceImpl.java

@@ -474,4 +474,14 @@ public class PassengerInfoServiceImpl implements PassengerInfoService {
         orderInfo.setGoodsTicket(new BigDecimal(goodsTicket));
         orderInfoService.update(orderInfo);
     }
+
+    @Override
+    public List<PassengerInfo> findByOpenIdAndStatus(String openId, String status,String payStatus) {
+        return passengerInfoDAO.findByOpenIdAndStatus(openId,status,payStatus);
+    }
+
+    @Override
+    public List<PassengerInfo> findByOpenIdAndVehicleShiftId(String openId, String vehicleShiftId, String status, String payStatus) {
+        return passengerInfoDAO.findByOpenIdAndVehicleShiftId(openId,vehicleShiftId,status,payStatus);
+    }
 }

+ 80 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/StationRemindServiceImpl.java

@@ -0,0 +1,80 @@
+package com.jpsoft.bus.modules.bus.service.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.annotation.Resource;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import com.jpsoft.bus.modules.bus.dao.StationRemindDAO;
+import com.jpsoft.bus.modules.bus.entity.StationRemind;
+import com.jpsoft.bus.modules.bus.service.StationRemindService;
+import com.github.pagehelper.Page;
+import com.jpsoft.bus.modules.common.dto.Sort;
+import com.github.pagehelper.PageHelper;
+
+@Transactional
+@Component(value="stationRemindService")
+public class StationRemindServiceImpl implements StationRemindService {
+	@Resource(name="stationRemindDAO")
+	private StationRemindDAO stationRemindDAO;
+
+	@Override
+	public StationRemind get(Long id) {
+		// TODO Auto-generated method stub
+		return stationRemindDAO.get(id);
+	}
+
+	@Override
+	public int insert(StationRemind model) {
+		// TODO Auto-generated method stub
+		//model.setId(UUID.randomUUID().toString());
+		
+		return stationRemindDAO.insert(model);
+	}
+
+	@Override
+	public int update(StationRemind model) {
+		// TODO Auto-generated method stub
+		return stationRemindDAO.update(model);		
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return stationRemindDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = stationRemindDAO.exist(id);
+		
+		return count > 0 ? true : false;
+	}
+	
+	@Override
+	public List<StationRemind> list() {
+		// TODO Auto-generated method stub
+		return stationRemindDAO.list();
+	}
+		
+	@Override
+	public Page<StationRemind> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
+        Page<StationRemind> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+            stationRemindDAO.search(searchParams,sortList);
+        });
+        
+        return page;
+	}
+
+	@Override
+	public List<StationRemind> findByAdvanceStationId(String currentStationId) {
+		return stationRemindDAO.findByAdvanceStationId(currentStationId);
+	}
+
+	@Override
+	public StationRemind findByOpenIdAndVehicleShiftId(String openId, String vehicleShiftId) {
+		return stationRemindDAO.findByOpenIdAndVehicleShiftId(openId,vehicleShiftId);
+	}
+}

+ 142 - 0
common/src/main/java/com/jpsoft/bus/modules/common/utils/SnowflakeIdWorker.java

@@ -0,0 +1,142 @@
+package com.jpsoft.bus.modules.common.utils;
+
+public class SnowflakeIdWorker {
+    private static SnowflakeIdWorker instance = new SnowflakeIdWorker(0,0);
+
+    /**
+     * 开始时间截 (2015-01-01)
+     */
+    private final long twepoch = 1420041600000L;
+    /**
+     * 机器id所占的位数
+     */
+    private final long workerIdBits = 5L;
+    /**
+     * 数据标识id所占的位数
+     */
+    private final long datacenterIdBits = 5L;
+    /**
+     * 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
+     */
+    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
+    /**
+     * 支持的最大数据标识id,结果是31
+     */
+    private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
+    /**
+     * 序列在id中占的位数
+     */
+    private final long sequenceBits = 12L;
+    /**
+     * 机器ID向左移12位
+     */
+    private final long workerIdShift = sequenceBits;
+    /**
+     * 数据标识id向左移17位(12+5)
+     */
+    private final long datacenterIdShift = sequenceBits + workerIdBits;
+    /**
+     * 时间截向左移22位(5+5+12)
+     */
+    private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
+    /**
+     * 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095)
+     */
+    private final long sequenceMask = -1L ^ (-1L << sequenceBits);
+    /**
+     * 工作机器ID(0~31)
+     */
+    private long workerId;
+    /**
+     * 数据中心ID(0~31)
+     */
+    private long datacenterId;
+    /**
+     * 毫秒内序列(0~4095)
+     */
+    private long sequence = 0L;
+    /**
+     * 上次生成ID的时间截
+     */
+    private long lastTimestamp = -1L;
+    /**
+     * 构造函数
+     * @param workerId     工作ID (0~31)
+     * @param datacenterId 数据中心ID (0~31)
+     */
+    public SnowflakeIdWorker(long workerId, long datacenterId) {
+        if (workerId > maxWorkerId || workerId < 0) {
+            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+        }
+        if (datacenterId > maxDatacenterId || datacenterId < 0) {
+            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
+        }
+        this.workerId = workerId;
+        this.datacenterId = datacenterId;
+    }
+    /**
+     * 获得下一个ID (该方法是线程安全的)
+     * @return SnowflakeId
+     */
+    public synchronized long nextId() {
+        long timestamp = timeGen();
+        // 如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
+        if (timestamp < lastTimestamp) {
+            throw new RuntimeException(
+                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+        }
+        // 如果是同一时间生成的,则进行毫秒内序列
+        if (lastTimestamp == timestamp) {
+            sequence = (sequence + 1) & sequenceMask;
+            // 毫秒内序列溢出
+            if (sequence == 0) {
+                //阻塞到下一个毫秒,获得新的时间戳
+                timestamp = tilNextMillis(lastTimestamp);
+            }
+        }
+        // 时间戳改变,毫秒内序列重置
+        else {
+            sequence = 0L;
+        }
+        // 上次生成ID的时间截
+        lastTimestamp = timestamp;
+        // 移位并通过或运算拼到一起组成64位的ID
+        return ((timestamp - twepoch) << timestampLeftShift) //
+                | (datacenterId << datacenterIdShift) //
+                | (workerId << workerIdShift) //
+                | sequence;
+    }
+    /**
+     * 阻塞到下一个毫秒,直到获得新的时间戳
+     * @param lastTimestamp 上次生成ID的时间截
+     * @return 当前时间戳
+     */
+    protected long tilNextMillis(long lastTimestamp) {
+        long timestamp = timeGen();
+        while (timestamp <= lastTimestamp) {
+            timestamp = timeGen();
+        }
+        return timestamp;
+    }
+    /**
+     * 返回以毫秒为单位的当前时间
+     * @return 当前时间(毫秒)
+     */
+    protected long timeGen() {
+        return System.currentTimeMillis();
+    }
+
+    public static SnowflakeIdWorker getInstance(){
+        return instance;
+    }
+
+
+    public static void main(String[] args) throws InterruptedException {
+        SnowflakeIdWorker idWorker = SnowflakeIdWorker.getInstance();
+        for (int i = 0; i < 10; i++) {
+            long id = idWorker.nextId();
+            Thread.sleep(1);
+            System.out.println(id);
+        }
+    }
+}

+ 75 - 11
common/src/main/java/com/jpsoft/bus/modules/common/utils/WechatMessageUtil.java

@@ -22,10 +22,8 @@ import java.util.regex.Pattern;
 @Slf4j
 @Component
 public class WechatMessageUtil {
-
-
     public static final String send_template = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
-
+    public static final String send_subscribe_template = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend?access_token=ACCESS_TOKEN";
     /**
      * 微信发送模版
      *
@@ -144,6 +142,80 @@ public class WechatMessageUtil {
         return result;
     }
 
+    public String sendSubscribeTemplate(String appId, String appSecret, String templateId, String openId, JSONObject sendData, String urlPath) {
+        String result = "";
+
+        try {
+            AccessToken accessToken = WeixinUtil.getAccessToken(appId, appSecret);
+
+            if (accessToken == null) {
+                throw new Exception("token无法获取");
+            }
+
+            //发送模版内容
+            String sendTemplateUrl = send_subscribe_template.replace("ACCESS_TOKEN", accessToken.getToken());
+
+            JSONObject sendTemplateData = new JSONObject();
+
+            sendTemplateData.put("touser", openId);
+            sendTemplateData.put("template_id", templateId);
+            sendTemplateData.put("page", urlPath);
+            sendTemplateData.put("data", sendData);
+
+            URL url = new URL(sendTemplateUrl);
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+            conn.setRequestMethod("POST");
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            conn.setUseCaches(false);
+            conn.setRequestProperty("Connection", "Keep-Alive");
+            conn.setRequestProperty("Charset", "UTF-8");
+
+            // 设置文件类型:
+            conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+
+            // 设置接收类型否则返回415错误
+            //conn.setRequestProperty("accept","*/*")此处为暴力方法设置接受所有类型,以此来防范返回415;
+            conn.setRequestProperty("accept", "application/json");
+            conn.setConnectTimeout(5000);
+            conn.setReadTimeout(5000);
+
+            String dataStr = sendTemplateData.toString();
+
+            log.warn("发送数据:" + dataStr);
+            // 往服务器里面发送数据
+            byte[] buffer = dataStr.getBytes("UTF-8");
+
+            // 设置文件长度
+            conn.setRequestProperty("Content-Length", String.valueOf(buffer.length));
+            OutputStream output = conn.getOutputStream();
+            output.write(buffer);
+            output.flush();
+            output.close();
+
+            if (conn.getResponseCode() == 200) {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
+
+                StringBuilder sb = new StringBuilder();
+                String line = "";
+
+                while ((line = reader.readLine()) != null) {
+                    sb.append(line);
+                }
+
+                result = sb.toString();
+
+                log.warn("接收数据:" + result);
+
+                reader.close();
+            }
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+        }
+
+        return result;
+    }
+
     public static String getContent(String content) {
         String finallyContent = content;
         String regex = "<p.*?>(.*?)</p>";
@@ -420,12 +492,4 @@ public class WechatMessageUtil {
 
         return ret;
     }
-
-
-    public static void main(String[] args) {
-
-
-    }
-
-
 }

+ 25 - 1
common/src/main/resources/mapper/bus/PassengerInfo.xml

@@ -218,7 +218,6 @@
             and status_ = #{status}
         </if>
     </select>
-
     <select id="findByShiftStatusPayStatusNotTicketDown" resultMap="PassengerInfoMap">
         <![CDATA[
 		select  * from bus_passenger_info
@@ -229,4 +228,29 @@
 		and ticket_down_station_id <> #{ticketDownStationId}
 		]]>
     </select>
+    <select id="findByOpenIdAndStatus" resultMap="PassengerInfoMap">
+        select t1.* from
+        bus_passenger_info t1
+        inner join base_order_info t2 on t2.passenger_id = t1.id_
+        inner join bus_shift_info t3 on t1.vehicle_shift_id = t3.id_
+        where t1.del_flag = 0
+        and t1.status_=#{status}
+        and t1.pay_status=#{payStatus}
+        and t3.status_='1'
+        and t2.update_by=#{openId}
+        order by t1.create_time desc
+    </select>
+    <select id="findByOpenIdAndVehicleShiftId" resultMap="PassengerInfoMap">
+        select t1.* from
+        bus_passenger_info t1
+        inner join base_order_info t2 on t2.passenger_id = t1.id_
+        inner join bus_shift_info t3 on t1.vehicle_shift_id = t3.id_
+        where t1.del_flag = 0
+        and t1.status_=#{status}
+        and t1.pay_status=#{payStatus}
+        and t2.update_by=#{openId}
+        and t3.status_='1'
+        and t3.id_ = #{vehicleShiftId}
+        order by t1.create_time asc
+    </select>
 </mapper>

+ 136 - 0
common/src/main/resources/mapper/bus/StationRemind.xml

@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.bus.modules.bus.dao.StationRemindDAO">
+    <resultMap id="StationRemindMap" type="com.jpsoft.bus.modules.bus.entity.StationRemind">
+        <id property="id" column="id_"/>
+        <result property="startStationId" column="start_station_id"/>
+        <result property="remindStationId" column="remind_station_id"/>
+        <result property="advanceStationId" column="advance_station_id"/>
+        <result property="stopInAdvance" column="stop_in_advance"/>
+        <result property="openId" column="open_id"/>
+        <result property="remindType" column="remind_type"/>
+        <result property="vehicleShiftId" column="vehicle_shift_id"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="delFlag" column="del_flag"/>
+    </resultMap>
+    <insert id="insert" parameterType="com.jpsoft.bus.modules.bus.entity.StationRemind">
+        <!--
+        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+            select sys_guid() from dual
+        </selectKey>
+        -->
+        <![CDATA[
+		insert into bus_station_remind
+	    (id_,start_station_id,remind_station_id,advance_station_id,
+	    stop_in_advance,open_id,remind_type,vehicle_shift_id,create_by,create_time,update_by,update_time,del_flag)
+		values
+		(
+            #{id,jdbcType= NUMERIC }
+            ,#{startStationId,jdbcType=VARCHAR}
+            ,#{remindStationId,jdbcType=VARCHAR}
+            ,#{advanceStationId,jdbcType=VARCHAR}
+            ,#{stopInAdvance,jdbcType= NUMERIC }
+            ,#{openId,jdbcType=VARCHAR}
+            ,#{remindType,jdbcType= NUMERIC }
+            ,#{vehicleShiftId,jdbcType=VARCHAR}
+            ,#{createBy,jdbcType=VARCHAR}
+            ,#{createTime,jdbcType= TIMESTAMP }
+            ,#{updateBy,jdbcType=VARCHAR}
+            ,#{updateTime,jdbcType= TIMESTAMP }
+            ,#{delFlag,jdbcType= NUMERIC }
+		)
+	]]>
+    </insert>
+    <delete id="delete" parameterType="string">
+        delete from bus_station_remind where id_=#{id,jdbcType=VARCHAR}
+    </delete>
+    <update id="update" parameterType="com.jpsoft.bus.modules.bus.entity.StationRemind">
+        update bus_station_remind
+        <set>
+            <if test="startStationId!=null">
+                start_station_id=#{startStationId,jdbcType=VARCHAR},
+            </if>
+            <if test="remindStationId!=null">
+                remind_station_id=#{remindStationId,jdbcType=VARCHAR},
+            </if>
+            <if test="stopInAdvance!=null">
+                stop_in_advance=#{stopInAdvance,jdbcType= NUMERIC },
+            </if>
+            <if test="advanceStationId!=null">
+                advance_station_id=#{advanceStationId,jdbcType=VARCHAR},
+            </if>
+            <if test="openId!=null">
+                open_id=#{openId,jdbcType=VARCHAR},
+            </if>
+            <if test="remindType!=null">
+                remind_type=#{remindType,jdbcType= NUMERIC },
+            </if>
+            <if test="vehicleShiftId!=null">
+                vehicle_shift_id=#{vehicleShiftId,jdbcType=VARCHAR},
+            </if>
+            <if test="createBy!=null">
+                create_by=#{createBy,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime!=null">
+                create_time=#{createTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="updateBy!=null">
+                update_by=#{updateBy,jdbcType=VARCHAR},
+            </if>
+            <if test="updateTime!=null">
+                update_time=#{updateTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="delFlag!=null">
+                del_flag=#{delFlag,jdbcType= NUMERIC },
+            </if>
+        </set>
+        where id_=#{id}
+    </update>
+    <select id="get" parameterType="long" resultMap="StationRemindMap">
+        select
+        id_,start_station_id,remind_station_id,stop_in_advance,advance_station_id,
+        open_id,remind_type,vehicle_shift_id,create_by,create_time,update_by,update_time,del_flag
+        from bus_station_remind
+        where id_=#{0}
+    </select>
+    <select id="exist" parameterType="string" resultType="int">
+        select count(*) from bus_station_remind where id_=#{0}
+    </select>
+    <select id="list" resultMap="StationRemindMap">
+        select * from bus_station_remind
+    </select>
+    <select id="search" parameterType="hashmap" resultMap="StationRemindMap">
+        <![CDATA[
+			select * from bus_station_remind
+		]]>
+        <where>
+            <if test="searchParams.openId != null">
+                and open_id = #{searchParams.openId}
+            </if>
+            <if test="searchParams.vehicleShiftId != null">
+                and vehicle_shift_id = #{searchParams.vehicleShiftId}
+            </if>
+        </where>
+        <foreach item="sort" collection="sortList" open="order by" separator=",">
+            ${sort.name} ${sort.order}
+        </foreach>
+    </select>
+    <select id="findByAdvanceStationId" parameterType="string" resultMap="StationRemindMap">
+        select * from bus_station_remind
+        where del_flag=0
+        and advance_station_id = #{0}
+        order by create_time asc
+    </select>
+    <select id="findByOpenIdAndVehicleShiftId" parameterType="string" resultMap="StationRemindMap">
+        select * from bus_station_remind
+        where del_flag=0
+        and open_id = #{openId}
+        and vehicle_shift_id = #{vehicleShiftId}
+        order by create_time asc
+    </select>
+</mapper>

+ 3 - 1
gps/src/main/java/com/jpsoft/gps/handler/ProcessHandler.java

@@ -44,7 +44,9 @@ public class ProcessHandler extends SimpleChannelInboundHandler<String> {
                     System.out.println(deviceNo + "," + df.format(gcj[1]) + "," + df.format(gcj[0]));
 
                     if (this.callback != null) {
-                        this.callback.receive(deviceNo, df.format(gcj[1]), df.format(gcj[0]));
+                        new Thread(()->{
+                            this.callback.receive(deviceNo, df.format(gcj[1]), df.format(gcj[0]));
+                        }).start();
                     }
                 }
             }

+ 2 - 1
web/src/main/java/com/jpsoft/bus/config/RabbitmqConfig.java

@@ -12,5 +12,6 @@ import java.util.Map;
 
 @Configuration
 public class RabbitmqConfig {
-
+    @Bean
+    public Queue StationRemindQueue() {return new Queue("stationRemindQueue", true);}
 }

+ 2 - 2
web/src/main/java/com/jpsoft/bus/config/WebMvcConfig.java

@@ -82,7 +82,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
 				.excludePathPatterns("/mobile/passengerApi/mergeInfo")
 				.excludePathPatterns("/mobile/passengerApi/passengerRecordList")
 				.excludePathPatterns("/mobile/passengerApi/routeShiftList")
-
-				;
+				.excludePathPatterns("/mobile/stationRemindApi/**")
+				.excludePathPatterns("/mobile/passengerApi/findCurrentVehicle");
 	}
 }

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

@@ -37,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
 import sun.security.krb5.internal.crypto.Des3;
 
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
@@ -92,7 +93,6 @@ public class PassengerApiController {
     @Autowired
     private StationInfoService stationInfoService;
 
-
     @PostMapping
     @ApiOperation(value = "通过车牌号查询详情")
     @ApiImplicitParams({
@@ -1555,5 +1555,4 @@ public class PassengerApiController {
 
         return messageResult;
     }
-
 }

+ 373 - 0
web/src/main/java/com/jpsoft/bus/modules/mobile/controller/StationRemindApiController.java

@@ -0,0 +1,373 @@
+package com.jpsoft.bus.modules.mobile.controller;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.bus.modules.bus.entity.*;
+import com.jpsoft.bus.modules.bus.service.*;
+import com.jpsoft.bus.modules.common.utils.PojoUtils;
+import com.jpsoft.bus.modules.common.dto.Sort;
+import com.jpsoft.bus.modules.common.dto.MessageResult;
+import com.jpsoft.bus.modules.common.utils.SnowflakeIdWorker;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Slf4j
+@RestController
+@RequestMapping("/mobile/stationRemindApi")
+@Api(description = "站点订阅")
+public class StationRemindApiController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private StationRemindService stationRemindService;
+
+    @Autowired
+    private StationInfoService stationInfoService;
+
+    @Autowired
+    private RabbitTemplate rabbitTemplate;
+
+    @Autowired
+    private ShiftInfoService shiftInfoService;
+
+    @Autowired
+    private VehicleInfoService vehicleInfoService;
+
+    @Autowired
+    private RouteInfoService routeInfoService;
+
+    @Autowired
+    private PassengerInfoService passengerInfoService;
+
+    @ApiOperation(value="添加订阅")
+    @PostMapping("add")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "startStationId", value = "起始站点编号", paramType = "form"),
+            @ApiImplicitParam(name = "remindStationId", value = "提醒站点编号", paramType = "form"),
+            @ApiImplicitParam(name = "stopInAdvance", value = "提前多少站通知", paramType = "form"),
+            @ApiImplicitParam(name = "remindType", value = "提醒类型(1-上车,2-下车)", paramType = "form"),
+            @ApiImplicitParam(name = "vehicleShiftId", value = "车辆班次编号", paramType = "form", allowEmptyValue = true),
+            @ApiImplicitParam(name = "openId", value = "微信openId", paramType = "form")
+    })
+    public MessageResult<StationRemind> add(String startStationId,String remindStationId,Integer stopInAdvance,
+                                            Integer remindType,String vehicleShiftId,String openId){
+        MessageResult<StationRemind> msgResult = new MessageResult<>();
+
+        try {
+            StationRemind stationRemind = new StationRemind();
+            stationRemind.setId(SnowflakeIdWorker.getInstance().nextId());
+            stationRemind.setStartStationId(startStationId);
+            stationRemind.setRemindStationId(remindStationId);
+            stationRemind.setStopInAdvance(stopInAdvance);
+
+            StationInfo advanceStation = getAdvanceStation(startStationId, remindStationId, stopInAdvance);
+
+            if(advanceStation!=null) {
+                stationRemind.setAdvanceStationId(advanceStation.getId());
+            }
+
+            stationRemind.setRemindType(remindType);
+            stationRemind.setVehicleShiftId(vehicleShiftId);
+            stationRemind.setOpenId(openId);
+            stationRemind.setDelFlag(false);
+            stationRemind.setCreateBy(openId);
+            stationRemind.setCreateTime(new Date());
+            
+            int affectCount = stationRemindService.insert(stationRemind);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(stationRemind);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("订阅失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="更新订阅")
+    @PostMapping("update")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "remindId", value = "订阅编号", paramType = "form"),
+            @ApiImplicitParam(name = "startStationId", value = "起始站点编号", paramType = "form"),
+            @ApiImplicitParam(name = "remindStationId", value = "提醒站点编号", paramType = "form"),
+            @ApiImplicitParam(name = "stopInAdvance", value = "提前多少站通知", paramType = "form"),
+            @ApiImplicitParam(name = "remindType", value = "提醒类型(1-上车,2-下车)", paramType = "form"),
+            @ApiImplicitParam(name = "vehicleShiftId", value = "车辆班次编号", paramType = "form", allowEmptyValue = true),
+            @ApiImplicitParam(name = "openId", value = "微信openId", paramType = "form")
+    })
+    public MessageResult<StationRemind> update(Long remindId,String startStationId,String remindStationId,Integer stopInAdvance,
+                                            Integer remindType,String vehicleShiftId,String openId){
+        MessageResult<StationRemind> msgResult = new MessageResult<>();
+
+        try {
+            StationRemind stationRemind = stationRemindService.get(remindId);
+            stationRemind.setStartStationId(startStationId);
+            stationRemind.setRemindStationId(remindStationId);
+            stationRemind.setStopInAdvance(stopInAdvance);
+
+            StationInfo advanceStation = getAdvanceStation(startStationId, remindStationId, stopInAdvance);
+
+            if(advanceStation!=null) {
+                stationRemind.setAdvanceStationId(advanceStation.getId());
+            }
+
+            stationRemind.setRemindType(remindType);
+            stationRemind.setVehicleShiftId(vehicleShiftId);
+            stationRemind.setOpenId(openId);
+            stationRemind.setDelFlag(false);
+            stationRemind.setCreateBy(openId);
+            stationRemind.setCreateTime(new Date());
+
+            int affectCount = stationRemindService.insert(stationRemind);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(stationRemind);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("订阅失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    private StationInfo getAdvanceStation(String startStationId, String remindStationId, Integer stopInAdvance) throws Exception {
+        StationInfo station = stationInfoService.get(remindStationId);
+
+        List<StationInfo> stationList = stationInfoService.findByRouteId(station.getRouteId());
+        StationInfo advanceStation = null;
+
+        if(stationList.size()>0){
+            StationInfo firstStation = stationList.get(0);
+
+            int curIndex = 0;
+
+            for(int i=0;i<stationList.size();i++){
+                if(stationList.get(i).getId().equals(remindStationId)){
+                    curIndex = i;
+                    break;
+                }
+            }
+
+            int advanceIndex = 0;
+
+            if (firstStation.getId().equals(startStationId)){
+                //首站->终点站
+                advanceIndex = curIndex - stopInAdvance;
+            }
+            else{
+                //终点站->首站
+                advanceIndex = curIndex + stopInAdvance;
+            }
+
+            if(advanceIndex<0){
+                advanceIndex = 0;
+            }
+
+            if (advanceIndex>=stationList.size()){
+                advanceIndex = stationList.size() - 1;
+            }
+
+            advanceStation = stationList.get(advanceIndex);
+        }
+        else{
+            throw new Exception("当前站点没有关联路线");
+        }
+        return advanceStation;
+    }
+
+    @ApiOperation(value="取消订阅")
+    @PostMapping("cancel")
+    public MessageResult<Integer> cancel(Long id){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+
+        try {
+            StationRemind stationRemind = stationRemindService.get(id);
+            stationRemind.setDelFlag(true);
+            stationRemind.setUpdateTime(new Date());
+
+            int affectCount = stationRemindService.update(stationRemind);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("取消订阅失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="列表")
+    @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    public MessageResult<Map> pageList(
+            String openId,
+            String vehicleShiftId,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize){
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("create_time","desc"));
+
+        if (StringUtils.isNotEmpty(openId)) {
+            searchParams.put("openId",openId);
+        }
+
+        if (StringUtils.isNotEmpty(vehicleShiftId)) {
+            searchParams.put("vehicleShiftId",vehicleShiftId);
+        }
+
+        Page<StationRemind> page = stationRemindService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
+
+        msgResult.setResult(true);
+        msgResult.setData(PojoUtils.pageWrapper(page));
+
+        return msgResult;
+    }
+
+    @GetMapping("sendMessage")
+    @ApiOperation(value="sendMessage")
+    public MessageResult<String> sendMessage(String shiftId){
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+            ShiftInfo shiftInfo = shiftInfoService.get(shiftId);
+            rabbitTemplate.convertAndSend("stationRemindQueue", shiftInfo);
+
+            messageResult.setResult(true);
+        }
+        catch (Exception ex){
+            log.error(ex.getMessage(),ex);
+
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
+
+    @GetMapping("findCurrentVehicle")
+    @ApiOperation(value="查询当前乘坐车辆")
+    public MessageResult<List> findCurrentVehicle(String openId){
+        MessageResult<List> messageResult = new MessageResult<>();
+
+        try {
+            List<PassengerInfo> passengers = passengerInfoService.findByOpenIdAndStatus(openId,"1", "2");
+
+            Set<String> vehicleShiftSet = new HashSet<>();
+
+            for (PassengerInfo passenger : passengers) {
+                if(!vehicleShiftSet.contains(passenger.getVehicleShiftId())){
+                    vehicleShiftSet.add(passenger.getVehicleShiftId());
+                }
+            }
+
+            List<Map> mapList = new ArrayList<>();
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+            for (String vehicleShiftId : vehicleShiftSet) {
+                Map<String,Object> map = new HashMap<>();
+                map.put("vehicleShiftId", vehicleShiftId);
+
+                ShiftInfo shiftInfo = shiftInfoService.get(vehicleShiftId);
+
+                VehicleInfo vehicleInfo = vehicleInfoService.get(shiftInfo.getVehicleId());
+                RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
+
+                map.put("createTime", sdf.format(shiftInfo.getCreateTime()));
+                map.put("licensePlateNumber", vehicleInfo.getLicensePlateNumber());
+                map.put("routeName", routeInfo.getName());
+
+                StationInfo startStation = stationInfoService.get(shiftInfo.getStartStationId());
+                StationInfo currentStation = stationInfoService.get(shiftInfo.getCurrentStationId());
+                StationInfo endStation = stationInfoService.get(shiftInfo.getEndStationId());
+
+                map.put("startStationId",startStation.getId());
+                map.put("startStationName",startStation.getName());
+                map.put("endStationId",endStation.getId());
+                map.put("endStationName",endStation.getName());
+
+                if(currentStation!=null){
+                    map.put("currentStationId",currentStation.getId());
+                    map.put("currentStationName",currentStation.getName());
+                }
+
+                //查询目的地
+                List<PassengerInfo> passengerInfos = passengerInfoService.findByOpenIdAndVehicleShiftId(openId,vehicleShiftId, "1" ,"2");
+
+                if (passengerInfos.size()>0){
+                    PassengerInfo passengerInfo = passengerInfos.get(0);
+                    StationInfo ticketDownStation = stationInfoService.get(passengerInfo.getTicketDownStationId());
+
+                    map.put("ticketDownStationId", ticketDownStation.getId());
+                    map.put("ticketDownStationName",ticketDownStation.getName());
+                }
+
+                //是否创建消息提醒,显示消息提醒的到达站点信息
+                map.put("openId",openId);
+
+                StationRemind stationRemind = stationRemindService.findByOpenIdAndVehicleShiftId(openId,vehicleShiftId);
+
+                if(stationRemind!=null){
+                    map.put("remindId", stationRemind.getId());
+                    map.put("stopInAdvance", stationRemind.getStopInAdvance());
+                }
+
+                mapList.add(map);
+            }
+
+            //todo 填写具体代码
+            messageResult.setData(mapList);
+            messageResult.setResult(true);
+        }
+        catch (Exception ex){
+            log.error(ex.getMessage(),ex);
+
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+}

+ 123 - 0
web/src/main/java/com/jpsoft/bus/modules/mq/listener/StationRemindListener.java

@@ -0,0 +1,123 @@
+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.service.RouteInfoService;
+import com.jpsoft.bus.modules.bus.service.StationInfoService;
+import com.jpsoft.bus.modules.bus.service.StationRemindService;
+import com.jpsoft.bus.modules.common.utils.CommonUtil;
+import com.jpsoft.bus.modules.common.utils.WechatMessageUtil;
+import lombok.extern.slf4j.Slf4j;
+import net.sf.json.JSONObject;
+import org.gavaghan.geodesy.Ellipsoid;
+import org.gavaghan.geodesy.GlobalCoordinates;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import java.text.DecimalFormat;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@Component
+@RabbitListener(queues = "stationRemindQueue")
+public class StationRemindListener {
+    @Autowired
+    private StationInfoService stationInfoService;
+
+    @Autowired
+    private StationRemindService stationRemindService;
+
+    @Autowired
+    private RouteInfoService routeInfoService;
+
+    @Value("${wx.stationRemindTemplateId}")
+    private String stationRemindTemplateId;
+
+    @Autowired
+    private WxConfig wxConfig;
+
+    @Autowired
+    private WechatMessageUtil wechatMessageUtil;
+
+    @RabbitHandler
+    public void process(ShiftInfo shiftInfo) {
+        try {
+            //查询站点提醒中设置当前站点到站提醒
+            List<StationRemind> stationRemindList = stationRemindService.findByAdvanceStationId(shiftInfo.getCurrentStationId());
+
+            RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
+            StationInfo startStation = stationInfoService.get(shiftInfo.getStartStationId());
+            StationInfo endStation = stationInfoService.get(shiftInfo.getEndStationId());
+
+            for (StationRemind stationRemind : stationRemindList) {
+                try {
+                    if (stationRemind.getRemindType() != null && stationRemind.getRemindType() == 2) {
+                        //下车提醒要判断是不是同一个班次
+                        if (!stationRemind.getVehicleShiftId().equals(shiftInfo.getId())) {
+                            continue;
+                        }
+                    }
+
+                    StationInfo remindStation = stationInfoService.get(stationRemind.getRemindStationId());
+                    StationInfo advanceStation = stationInfoService.get(stationRemind.getAdvanceStationId());
+
+                    String templateId = stationRemindTemplateId;
+                    JSONObject sendData = new JSONObject();
+
+                    JSONObject thing4 = new JSONObject();
+                    thing4.put("value", routeInfo.getName() + "(" + startStation.getName() + "," + endStation.getName() + ")");
+                    sendData.put("thing4", thing4);
+
+                    JSONObject thing2 = new JSONObject();
+                    thing2.put("value", advanceStation.getName());
+                    sendData.put("thing2", thing2);
+
+                    JSONObject thing6 = new JSONObject();
+                    thing6.put("value", String.format("大约%s",
+                            getDistance(remindStation, advanceStation)));
+                    sendData.put("thing6", thing6);
+
+                    JSONObject thing3 = new JSONObject();
+                    thing3.put("value", String.format("距离目的站点(%s)还有%s站", remindStation.getName(), stationRemind.getStopInAdvance()));
+                    sendData.put("thing3", thing3);
+
+                    wechatMessageUtil.sendSubscribeTemplate(wxConfig.getAppId(), wxConfig.getAppSecret(), templateId, stationRemind.getOpenId(), sendData, "");
+
+                    stationRemind.setDelFlag(true);
+                    stationRemind.setUpdateTime(new Date());
+
+                    stationRemindService.update(stationRemind);
+                } catch (Exception ex) {
+                    log.error(ex.getMessage(), ex);
+                }
+            }
+        }
+        catch (Exception e){
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    private String getDistance(StationInfo remindStation, StationInfo advanceStation) {
+        String distance = "";
+        GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(advanceStation.getLatitude()), Double.valueOf(advanceStation.getLongitude()));
+        GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(remindStation.getLatitude()), Double.valueOf(remindStation.getLongitude()));
+
+        Double meter = CommonUtil.getDistanceMeter(source, target, Ellipsoid.Sphere);
+        DecimalFormat df = new DecimalFormat("0.00");
+
+        if (meter>1000){
+            distance = df.format(meter/1000) + "千米";
+        }
+        else{
+            distance = meter.intValue() + "米";
+        }
+
+        return distance;
+    }
+}

+ 9 - 9
web/src/main/resources/application-dev.yml

@@ -7,14 +7,14 @@ spring:
   datasource:
 
     #开发环境
-#     url: jdbc:log4jdbc:mysql://192.168.33.20:3306/smart-bus?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
-#     username: root
-#     password: jpsoft2016
+     url: jdbc:log4jdbc:mysql://192.168.33.20:3306/smart-bus?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+     username: root
+     password: jpsoft2016
 
     #测试环境
-     url: jdbc:log4jdbc:mysql://47.92.161.104:3336/smart-bus?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
-     username: root
-     password: jpsoft8121234
+#     url: jdbc:log4jdbc:mysql://47.92.161.104:3336/smart-bus?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+#     username: root
+#     password: jpsoft8121234
 
     #正式环境
 #     url: jdbc:log4jdbc:mysql://122.189.98.152:3336/jp_housekeeper?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
@@ -37,9 +37,9 @@ logger:
 
 wx:
   pay:
-    #企业联合会
-    appId: wx343bf93d2a3dc8af
-    appSecret: ac61fa669a7a79c7d2a8188ff7ddaef6
+    #车信达
+    appId: wx93675268c87a5a46
+    appSecret: 8a55e8cc8cffbf2db66f3024311036bc
     mchId: 1500160622
     subMchId: 1505070291
     mchKey: jpsoft11111111111111111111111111

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

@@ -27,7 +27,7 @@ spring:
     username: admin
     password: jpsoft
     #虚拟host 可以不设置,使用server默认host
-    virtual-host: housekeeper-test
+    virtual-host: smart-bus-test
 
 logger:
   level: WARN

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

@@ -128,6 +128,7 @@ alipay:
 
 wx:
   commonAccessTokenUrl: "http://ykt.xiaoxinda.com/weixin/token"
+  stationRemindTemplateId: "Ilxy2TX264A3RHqRyDZqL_xUDxi9OuBNeJoDOBfMRHg"
   pay:
     appId: wxe598c699aa68cffe
     appSecret: ea20d2e9a36aace26b4f7654218129af