From b31091da56446f57d21c41d009ce7b55a70a9789 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期四, 19 六月 2025 11:59:31 +0800 Subject: [PATCH] 优化报警 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/WarnController.java | 67 ++++++++++++++++++++++++++++++--- 1 files changed, 61 insertions(+), 6 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/WarnController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/WarnController.java index a2652cc..9ef5e24 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/WarnController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/WarnController.java @@ -1,5 +1,7 @@ package com.ruoyi.system.controller; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.web.page.PageInfo; @@ -15,16 +17,21 @@ import com.ruoyi.system.service.IWarnService; import com.ruoyi.system.util.GDMapGeocodingUtil; import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.usermodel.Workbook; 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.IOException; import java.math.BigDecimal; +import java.net.URLEncoder; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,28 +57,65 @@ @GetMapping("/getCarWarnList") @ApiOperation(value = "获取车辆预警列表数据", tags = {"车辆管理", "预警记录", "首页"}) - public R<PageInfo<CarWarnListResp>> getCarWarnList(CarWarnListReq carWarnListReq) { + public R<Map<String, Object>> getCarWarnList(CarWarnListReq carWarnListReq) { PageInfo<CarWarnListResp> pageInfo = warnService.getCarWarnList(carWarnListReq); - return R.ok(pageInfo); + Map<String, Object> map = new HashMap<>(); + map.put("page", pageInfo); + List<Warn> list = warnService.getAllCarWarnList(carWarnListReq); + map.put("total", list.size()); + map.put("processed", list.stream().filter(s->!s.getTreatmentState().equals("处理中")).count()); + map.put("unprocessed", list.stream().filter(s->s.getTreatmentState().equals("处理中")).count()); + return R.ok(map); + } + + + @GetMapping("/exportCarWarnList") + @ApiOperation(value = "导出车辆预警列表数据", tags = {"预警记录"}) + public void exportCarWarnList(CarWarnListReq carWarnListReq, HttpServletResponse response) { + carWarnListReq.setPageSize(99999); + PageInfo<CarWarnListResp> pageInfo = warnService.getCarWarnList(carWarnListReq); + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), CarWarnListResp.class, pageInfo.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("/getCarWarnInfo") @ApiOperation(value = "获取车辆预警详情数据", tags = {"车辆管理", "预警记录"}) - public R<CarWarnInfoResp> getCarWarnInfo(@PathVariable("vehicleNumber") String vehicleNumber) { + public R<CarWarnInfoResp> getCarWarnInfo(String vehicleNumber) { Car car = carService.getOne(new LambdaQueryWrapper<Car>().eq(Car::getVehicleNumber, vehicleNumber)); if (null == car) { return R.ok(); } String time = LocalDateTime.now().minusMinutes(15).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - List<Warn> list = warnService.list(new LambdaQueryWrapper<Warn>().eq(Warn::getCarId, car.getId()).lt(Warn::getStartTime, time).orderByDesc(Warn::getCreateTime)); + List<Warn> list = warnService.list(new LambdaQueryWrapper<Warn>().eq(Warn::getCarId, car.getId()).gt(Warn::getStartTime, time).orderByDesc(Warn::getStartTime)); CarWarnInfoResp carWarnInfoResp = new CarWarnInfoResp(); carWarnInfoResp.setVehicleNumber(vehicleNumber); GnssDataVo gnssDataVo = upExgMsgRealLocationClient.getVehicleSpeed(vehicleNumber).getData(); carWarnInfoResp.setSpeed(new BigDecimal(gnssDataVo.getVec1())); Map<String, String> geocode = null; try { - geocode = GDMapGeocodingUtil.geocode(Double.valueOf(gnssDataVo.getLon() / 1000000).toString(), Double.valueOf(gnssDataVo.getLat() / 1000000).toString()); + String longitude = new BigDecimal(gnssDataVo.getLon()).divide(new BigDecimal(1000000)).toString(); + String latitude = new BigDecimal(gnssDataVo.getLat()).divide(new BigDecimal(1000000)).toString(); + geocode = GDMapGeocodingUtil.geocode(longitude, latitude); } catch (Exception e) { throw new RuntimeException(e); } @@ -86,6 +130,7 @@ warnResp.setLon(new BigDecimal(warn.getLongitude())); warnResp.setLat(new BigDecimal(warn.getLatitude())); warnResp.setAddress(warn.getAddress()); + warnResp.setImageUrl(warn.getPicUrl()); warnList.add(warnResp); } carWarnInfoResp.setWarnList(warnList); @@ -105,4 +150,14 @@ List<Map<String, Object>> warnGroupCountTop10 = warnService.getWarnGroupCountTop10(); return R.ok(warnGroupCountTop10); } + + + + + @GetMapping("/getAllWarnGroupVehicleType") + @ApiOperation(value = "获取根据车辆类型的报警汇总数据", tags = {"首页"}) + public R<List<Map<String, Object>>> getAllWarnGroupVehicleType(){ + List<Map<String, Object>> allWarnGroupVehicleType = warnService.getAllWarnGroupVehicleType(); + return R.ok(allWarnGroupVehicleType); + } } -- Gitblit v1.7.1