From 35b0088fa28dab8a28758dcbcc056620c1ea5e2c Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期五, 30 五月 2025 11:02:35 +0800 Subject: [PATCH] 修改公交公司的事件订阅功能 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java | 155 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 138 insertions(+), 17 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java index d8c7f37..2e2b60b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java @@ -1,5 +1,8 @@ package com.ruoyi.system.controller; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; +import cn.hutool.core.io.FileUtil; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.dataInterchange.api.feignClient.PlaybackMsgClient; @@ -16,26 +19,43 @@ import com.ruoyi.system.service.IDriverService; import com.ruoyi.system.service.IEnterpriseService; import com.ruoyi.system.service.IOrderService; +import com.ruoyi.system.util.JavaCVStreamUtil; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.net.URLEncoder; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.util.List; /** +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** * @author zhibing.pu * @Date 2025/3/24 17:50 */ +@Slf4j @RestController @RequestMapping("/order") public class OrderController { - + @Resource private IOrderService orderService; @@ -54,16 +74,63 @@ @Resource private PlaybackMsgClient playbackMsgClient; + @Resource + private RedisTemplate redisTemplate; + @Value("${live.hls.output-path}") + private String hlsOutputPath; + + @Value("${live.hls.ip}") + private String hlsIp; + + @Value("${live.hls.port}") + private Integer hlsPort; + + @Value("${live.flv.ip}") + private String flvIp; + + @Value("${live.flv.rtmp-port}") + private Integer flvRtmpPort; + + @Value("${live.flv.http-port}") + private Integer flvHttpPort; @GetMapping("/getOrderList") @ApiOperation(value = "获取订单列表", tags = {"车辆管理", "订单管理"}) - public R<PageInfo<Order>> getOrderList(OrderListReq req){ + public R<PageInfo<Order>> getOrderList(OrderListReq req) { PageInfo<Order> orderList = orderService.getOrderList(req); return R.ok(orderList); } + + @GetMapping("/exportOrderList") + @ApiOperation(value = "导出订单列表", tags = {"订单管理"}) + public void exportOrderList(OrderListReq req, HttpServletResponse response) { + req.setPageSize(99999); + PageInfo<Order> orderList = orderService.getOrderList(req); + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), Order.class, orderList.getRecords()); + response.setCharacterEncoding("utf-8"); + ServletOutputStream outputStream = null; + try { + String fileName = URLEncoder.encode("订单列表.xls", "utf-8"); + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + response.setHeader("Pragma", "no-cache"); + response.setHeader("Cache-Control", "no-cache"); + outputStream = response.getOutputStream(); + workbook.write(outputStream); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + workbook.close(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } @GetMapping("/getOrderInfo/{id}") @@ -71,20 +138,24 @@ @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "id", required = true) }) - public R<Order> getOrderInfo(@PathVariable("id") Integer id){ + public R<Order> getOrderInfo(@PathVariable("id") Integer id) { Order order = orderService.getById(id); - if(null == order){ + if (null == order) { return R.fail("失败"); } Driver driver = driverService.getById(order.getDriverId()); Car car = carService.getById(order.getCarId()); Enterprise enterprise = enterpriseService.getById(order.getEnterpriseId()); - order.setDriverName(driver.getName()); + if (null != driver) { + order.setDriverName(driver.getName()); + order.setDriverPhone(driver.getPhone()); + order.setDrivingLicenseNumber(driver.getDrivingLicenseNumber()); + } order.setVehicleNumber(car.getVehicleNumber()); + order.setDeviceId(car.getDeviceId()); order.setEnterpriseName(enterprise.getName()); return R.ok(order); } - @GetMapping("/getOrderTravel") @@ -92,9 +163,9 @@ @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "id", required = true) }) - public R<List<OrderTravelVo>> getOrderTravel(@PathVariable("id") Integer id){ + public R<List<OrderTravelVo>> getOrderTravel(Integer id) { Order order = orderService.getById(id); - if(null == order){ + if (null == order) { return R.fail("失败"); } Car car = carService.getById(order.getCarId()); @@ -106,31 +177,81 @@ } - @GetMapping("/getOrderMonitoring") @ApiOperation(value = "获取订单监控", tags = {"订单管理"}) @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "id", required = true) }) - public R<RealVideoResp> getOrderMonitoring(@PathVariable("id") Integer id){ + public R<RealVideoResp> getOrderMonitoring(Integer id) { Order order = orderService.getById(id); - if(null == order){ - return R.fail("失败"); + if (null == order) { + return R.fail("发起实时音视频失败,可能是车辆离线导致"); } Car car = carService.getById(order.getCarId()); + //手动加一次状态数据,避免定时任务结束任务线程 + redisTemplate.opsForValue().set("live:" + order.getCarId(), true, 1, TimeUnit.MINUTES); Enterprise enterprise = enterpriseService.getById(car.getEnterpriseId()); LocalDateTime dateTime = LocalDateTime.parse(order.getOrderTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); long startTime = dateTime.toEpochSecond(ZoneOffset.ofHours(8)); long endTime = dateTime.plusDays(1).toEpochSecond(ZoneOffset.ofHours(8)); R<UPPlaybackMsgStartupAckVo> startupAckVoR = playbackMsgClient.playbackMsgStartup(Integer.valueOf(enterprise.getCode()), car.getVehicleNumber(), startTime, endTime); - if(200 == startupAckVoR.getCode()){ + if (200 == startupAckVoR.getCode()) { UPPlaybackMsgStartupAckVo data = startupAckVoR.getData(); RealVideoResp resp = new RealVideoResp(); - resp.setServerIp(data.getServerIP()); - resp.setServerPort(data.getServerPort()); + //执行拉流和推流 +// live_hls(data.getUrl(), car); +// resp.setServerIp(hlsIp); +// resp.setServerPort(hlsPort); + resp.setUrl(data.getUrl()); +// live_flv(data.getUrl(), car.getId()); + resp.setServerIp(flvIp); + resp.setServerPort(flvHttpPort); return R.ok(resp); } - return R.fail(startupAckVoR.getMsg()); + log.error("获取视频失败:{}", startupAckVoR.getMsg()); + return R.fail("发起实时音视频失败,可能是车辆离线导致"); + } + + + public void live_hls(String input, Car car){ + String path = hlsOutputPath + "hls\\" + car.getVehicleNumber() + "\\live.m3u8"; + String folderPath = hlsOutputPath + "hls\\" + car.getVehicleNumber(); + FileUtil.mkParentDirs(path); + File file = new File(path); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + //执行拉流和推流 + ExecutorService executorService = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>()); + executorService.execute(new Runnable() { + @Override + public void run() { + JavaCVStreamUtil.push_hls(input, path, car.getId(), folderPath); + } + }); + carService.taskPlayDetection(car.getId()); + } + + public void live_flv(String input, Integer id){ + String url = "rtmp://" + flvIp + ":" + flvRtmpPort + "/flv/" + id; + //执行拉流和推流 + ExecutorService executorService = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>()); + executorService.execute(new Runnable() { + @Override + public void run() { + JavaCVStreamUtil.push_flv(input, url, id); + } + }); + carService.taskPlayDetection(id); } } -- Gitblit v1.7.1