From 844bc318aee73ddcc7927e3b0ac8022c1ad74d84 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Mon, 15 Dec 2025 08:33:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(videoreview):=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=9C=BA=E4=BD=8D=E8=AF=84=E4=BB=B7=E6=95=B0=E6=8D=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改机位评价数据结构从嵌套Map改为简单Map - 更新数据库映射文件中的类型处理器配置 - 调整评价统计逻辑以适应新的数据结构 - 优化导出功能以支持新格式的机位评价展示 - 更新相关实体类、DTO类及Mapper接口定义 - 移除不再使用的嵌套Map相关代码和依赖 --- .../ycwl/basic/mapper/VideoReviewMapper.java | 4 +- .../videoreview/dto/VideoReviewAddReqDTO.java | 7 +- .../videoreview/dto/VideoReviewRespDTO.java | 6 +- .../dto/VideoReviewStatisticsRespDTO.java | 4 +- .../videoreview/entity/VideoReviewEntity.java | 10 +-- .../service/impl/VideoReviewServiceImpl.java | 75 ++++++------------- .../resources/mapper/VideoReviewMapper.xml | 2 +- 7 files changed, 38 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/ycwl/basic/mapper/VideoReviewMapper.java b/src/main/java/com/ycwl/basic/mapper/VideoReviewMapper.java index 4f8c559f..2339971b 100644 --- a/src/main/java/com/ycwl/basic/mapper/VideoReviewMapper.java +++ b/src/main/java/com/ycwl/basic/mapper/VideoReviewMapper.java @@ -65,7 +65,7 @@ public interface VideoReviewMapper extends BaseMapper { /** * 查询所有机位评价数据(用于后端计算平均值) * - * @return 机位评价列表(嵌套Map结构) + * @return 机位评价列表(Map结构: 机位ID -> 评分) */ - List>> selectAllCameraPositionRatings(); + List> selectAllCameraPositionRatings(); } diff --git a/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewAddReqDTO.java b/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewAddReqDTO.java index 13b1cee1..5beca3d8 100644 --- a/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewAddReqDTO.java +++ b/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewAddReqDTO.java @@ -27,9 +27,8 @@ public class VideoReviewAddReqDTO { /** * 机位评价JSON(可选) - * 格式: {"12345": {"清晰度":5,"构图":4,"色彩":5,"整体效果":4}, "12346": {...}} - * 外层key为机位ID,内层Map为该机位的各维度评分 - * 评分维度: 清晰度, 构图, 色彩, 整体效果 + * 格式: {"12345": 5, "12346": 4} + * key为机位ID,value为该机位的评分(1-5) */ - private Map> cameraPositionRating; + private Map cameraPositionRating; } diff --git a/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewRespDTO.java b/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewRespDTO.java index 7b8dd088..d4f0470c 100644 --- a/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewRespDTO.java +++ b/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewRespDTO.java @@ -69,10 +69,10 @@ public class VideoReviewRespDTO { /** * 机位评价JSON - * 格式: {"12345": {"清晰度":5,"构图":4,"色彩":5,"整体效果":4}, "12346": {...}} - * 外层key为机位ID,内层Map为该机位的各维度评分 + * 格式: {"12345": 5, "12346": 4} + * key为机位ID,value为该机位的评分(1-5) */ - private Map> cameraPositionRating; + private Map cameraPositionRating; /** * 创建时间 diff --git a/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewStatisticsRespDTO.java b/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewStatisticsRespDTO.java index fb36dc7f..e58d0e82 100644 --- a/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewStatisticsRespDTO.java +++ b/src/main/java/com/ycwl/basic/model/pc/videoreview/dto/VideoReviewStatisticsRespDTO.java @@ -40,8 +40,8 @@ public class VideoReviewStatisticsRespDTO { private List scenicRankList; /** - * 机位评价维度统计 - * key: 维度名称, value: 平均分 + * 机位评价统计 + * key: 机位ID, value: 该机位的平均评分 */ private Map cameraPositionAverage; diff --git a/src/main/java/com/ycwl/basic/model/pc/videoreview/entity/VideoReviewEntity.java b/src/main/java/com/ycwl/basic/model/pc/videoreview/entity/VideoReviewEntity.java index 888a64fc..b029492d 100644 --- a/src/main/java/com/ycwl/basic/model/pc/videoreview/entity/VideoReviewEntity.java +++ b/src/main/java/com/ycwl/basic/model/pc/videoreview/entity/VideoReviewEntity.java @@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.ycwl.basic.handler.NestedMapTypeHandler; +import com.ycwl.basic.handler.MapTypeHandler; import lombok.Data; import org.apache.ibatis.type.JdbcType; @@ -51,11 +51,11 @@ public class VideoReviewEntity { /** * 机位评价JSON - * 格式: {"12345": {"清晰度":5,"构图":4,"色彩":5,"整体效果":4}, "12346": {...}} - * 外层key为机位ID,内层Map为该机位的各维度评分 + * 格式: {"12345": 5, "12346": 4} + * key为机位ID,value为该机位的评分(1-5) */ - @TableField(typeHandler = NestedMapTypeHandler.class, jdbcType = JdbcType.VARCHAR) - private Map> cameraPositionRating; + @TableField(typeHandler = MapTypeHandler.class, jdbcType = JdbcType.VARCHAR) + private Map cameraPositionRating; /** * 创建时间 diff --git a/src/main/java/com/ycwl/basic/service/impl/VideoReviewServiceImpl.java b/src/main/java/com/ycwl/basic/service/impl/VideoReviewServiceImpl.java index de5a6c10..69a585e7 100644 --- a/src/main/java/com/ycwl/basic/service/impl/VideoReviewServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/impl/VideoReviewServiceImpl.java @@ -31,7 +31,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; -import java.util.stream.Collectors; /** * 视频评价Service实现类 @@ -160,7 +159,7 @@ public class VideoReviewServiceImpl implements VideoReviewService { // 2. 收集所有机位ID并批量查询机位名称 Set allDeviceIds = new LinkedHashSet<>(); for (VideoReviewRespDTO review : list) { - Map> cameraRating = review.getCameraPositionRating(); + Map cameraRating = review.getCameraPositionRating(); if (cameraRating != null && !cameraRating.isEmpty()) { // 收集机位ID (按顺序) for (String deviceIdStr : cameraRating.keySet()) { @@ -195,12 +194,7 @@ public class VideoReviewServiceImpl implements VideoReviewService { headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - // 5. 创建单元格自动换行样式 - CellStyle wrapStyle = workbook.createCellStyle(); - wrapStyle.setWrapText(true); - wrapStyle.setVerticalAlignment(VerticalAlignment.TOP); - - // 6. 生成动态表头 - 使用机位名称作为表头 + // 5. 生成动态表头 - 使用机位名称作为表头 Row headerRow = sheet.createRow(0); List headerList = new ArrayList<>(); headerList.add("评价ID"); @@ -228,7 +222,7 @@ public class VideoReviewServiceImpl implements VideoReviewService { cell.setCellStyle(headerStyle); } - // 7. 填充数据 + // 6. 填充数据 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int rowNum = 1; @@ -246,37 +240,21 @@ public class VideoReviewServiceImpl implements VideoReviewService { row.createCell(colIndex++).setCellValue(review.getContent()); // 机位评价列 - 按表头顺序填充 - Map> cameraRating = review.getCameraPositionRating(); + Map cameraRating = review.getCameraPositionRating(); for (Long deviceId : sortedDeviceIds) { String deviceIdStr = String.valueOf(deviceId); - Map dimensions = null; + Integer rating = null; if (cameraRating != null && cameraRating.containsKey(deviceIdStr)) { - dimensions = cameraRating.get(deviceIdStr); - } - - // 构建单元格内容: 只显示评分维度(不再重复机位名称) - StringBuilder cellContent = new StringBuilder(); - - if (dimensions != null && !dimensions.isEmpty()) { - // 按维度名排序,保证一致性 - List> sortedDimensions = dimensions.entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .collect(Collectors.toList()); - - boolean first = true; - for (Map.Entry dimEntry : sortedDimensions) { - if (!first) { - cellContent.append("\n"); - } - cellContent.append(dimEntry.getKey()).append(":").append(dimEntry.getValue()); - first = false; - } + rating = cameraRating.get(deviceIdStr); } Cell cell = row.createCell(colIndex++); - cell.setCellValue(cellContent.toString()); - cell.setCellStyle(wrapStyle); + if (rating != null) { + cell.setCellValue(rating); + } else { + cell.setCellValue(""); + } } // 时间列 @@ -284,17 +262,12 @@ public class VideoReviewServiceImpl implements VideoReviewService { row.createCell(colIndex).setCellValue(review.getUpdateTime() != null ? sdf.format(review.getUpdateTime()) : ""); } - // 8. 自动调整列宽 + // 7. 自动调整列宽 for (int i = 0; i < headerList.size(); i++) { sheet.autoSizeColumn(i); - // 对于机位列,设置最小宽度以便换行内容显示完整 - if (i >= 7 && i < 7 + sortedDeviceIds.size()) { - int currentWidth = sheet.getColumnWidth(i); - sheet.setColumnWidth(i, Math.max(currentWidth, 5000)); // 最小25个字符宽度 - } } - // 9. 写入输出流 + // 8. 写入输出流 workbook.write(outputStream); workbook.close(); @@ -302,32 +275,28 @@ public class VideoReviewServiceImpl implements VideoReviewService { } /** - * 计算机位评价各维度的平均值 + * 计算各机位的平均评分 */ private Map calculateCameraPositionAverage() { - List>> allRatings = videoReviewMapper.selectAllCameraPositionRatings(); + List> allRatings = videoReviewMapper.selectAllCameraPositionRatings(); if (allRatings == null || allRatings.isEmpty()) { return new HashMap<>(); } - // 统计各维度的总分和次数 - Map> dimensionScores = new HashMap<>(); - for (Map> rating : allRatings) { + // 统计各机位的总分和次数 + Map> deviceScores = new HashMap<>(); + for (Map rating : allRatings) { if (rating == null) continue; - // 遍历每个机位 - for (Map deviceRatings : rating.values()) { - if (deviceRatings == null) continue; - // 遍历该机位的每个维度 - for (Map.Entry entry : deviceRatings.entrySet()) { - dimensionScores.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(entry.getValue()); - } + // 遍历每个机位的评分 + for (Map.Entry entry : rating.entrySet()) { + deviceScores.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(entry.getValue()); } } // 计算平均值 Map result = new HashMap<>(); - for (Map.Entry> entry : dimensionScores.entrySet()) { + for (Map.Entry> entry : deviceScores.entrySet()) { double avg = entry.getValue().stream().mapToInt(Integer::intValue).average().orElse(0.0); result.put(entry.getKey(), BigDecimal.valueOf(avg).setScale(2, RoundingMode.HALF_UP)); } diff --git a/src/main/resources/mapper/VideoReviewMapper.xml b/src/main/resources/mapper/VideoReviewMapper.xml index dda53b37..e056e690 100644 --- a/src/main/resources/mapper/VideoReviewMapper.xml +++ b/src/main/resources/mapper/VideoReviewMapper.xml @@ -16,7 +16,7 @@ + typeHandler="com.ycwl.basic.handler.MapTypeHandler"/>