|
@@ -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;
|
|
|
|
+ }
|
|
|
|
+}
|