websocket早晚高峰推送

master
chents 3 years ago
parent fed414113a
commit f468902027
  1. 26
      src/main/java/org/springblade/modules/business/controller/CommonApiController.java
  2. 27
      src/main/java/org/springblade/modules/business/controller/MorningEveningController.java

@ -1,5 +1,6 @@
package org.springblade.modules.business.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
@ -19,10 +20,8 @@ import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.entity.BusLine;
import org.springblade.modules.business.entity.CarAdmin;
import org.springblade.modules.business.entity.CarLiveChannel;
import org.springblade.modules.business.service.ICarAdminService;
import org.springblade.modules.business.service.ICarInfoService;
import org.springblade.modules.business.service.ICarLiveChannelService;
import org.springblade.modules.business.service.IStationHintService;
import org.springblade.modules.business.entity.MorningEvening;
import org.springblade.modules.business.service.*;
import org.springblade.modules.business.service.impl.PublishService;
import org.springblade.modules.business.vo.CarInfoVO;
import org.springblade.modules.business.vo.SiteInfoVO;
@ -64,6 +63,8 @@ public class CommonApiController extends BladeController {
private final ICarLiveChannelService carLiveChannelService;
private final IMorningEveningService morningEveningService;
/**
* 设置车牌号
*
@ -137,17 +138,20 @@ public class CommonApiController extends BladeController {
*/
@GetMapping("get-rush-hour")
public R getRushHour() {
List<Map<String, String>> rushHourList = new ArrayList<>();
Map<String, String> morning = new ArrayMap<>();
QueryWrapper<MorningEvening> queryWrapper = new QueryWrapper<>();
queryWrapper.select("morning_start","morning_end","evening_start","evening_end");
MorningEvening morningEveningVo = morningEveningService.getOne(queryWrapper);
List<Map<String, Object>> rushHourList = new ArrayList<>();
Map<String, Object> morning = new ArrayMap<>();
morning.put("name", "早高峰");
morning.put("starttime", "7:30");
morning.put("endtime", "8:30");
morning.put("starttime", morningEveningVo.getMorningStart());
morning.put("endtime", morningEveningVo.getMorningEnd());
rushHourList.add(morning);
Map<String, String> evening = new ArrayMap<>();
Map<String, Object> evening = new ArrayMap<>();
evening.put("name", "晚高峰");
evening.put("starttime", "17:30");
evening.put("endtime", "18:30");
evening.put("starttime", morningEveningVo.getEveningStart());
evening.put("endtime", morningEveningVo.getEveningEnd());
rushHourList.add(evening);
return R.data(rushHourList);

@ -1,21 +1,26 @@
package org.springblade.modules.business.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.cache.business.CarInfoCache;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tenant.annotation.TenantDS;
import org.springblade.core.tool.api.R;
import org.springblade.modules.business.entity.MorningEvening;
import org.springblade.modules.business.service.IMorningEveningService;
import org.springblade.modules.websocket.service.WebsocketService;
import org.springblade.modules.websocket.vo.WebSocketMessage;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 控制器
@ -32,6 +37,11 @@ public class MorningEveningController extends BladeController {
private final IMorningEveningService morningEveningService;
private final WebsocketService websocketService;
private static final String MORNING_EVENING = "morning-evening";
private static final String WEB = "web";
/**
* 查询所有数据
@ -57,6 +67,23 @@ public class MorningEveningController extends BladeController {
public R update(@RequestBody MorningEvening morningEvening) {
boolean result = morningEveningService.updateById(morningEvening);
if (result) {
QueryWrapper<MorningEvening> queryWrapper = new QueryWrapper<>();
queryWrapper.select("id","morning_start","morning_end","evening_start","evening_end");
queryWrapper.eq("id",morningEvening.getId());
MorningEvening morningEveningVo = morningEveningService.getOne(queryWrapper);
WebSocketMessage message = new WebSocketMessage();
Map<String, Object> morningEveningMap= new HashMap<>();
morningEveningMap.put("morningStart",morningEveningVo.getMorningStart());
morningEveningMap.put("morningEnd",morningEveningVo.getMorningEnd());
morningEveningMap.put("eveningStart",morningEveningVo.getEveningStart());
morningEveningMap.put("eveningEnd",morningEveningVo.getEveningEnd());
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("msgType", MORNING_EVENING);
dataMap.put("data", morningEveningMap);
message.setTitle(WEB);
message.setCode(200);
message.setContent(JSON.toJSONString(dataMap));
websocketService.broadcast(message);
return R.success("修改成功");
} else {
return R.fail("修改失败");

Loading…
Cancel
Save