You've already forked FrameTour-BE
feat(video-review): 支持机位多维度评价功能
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
- 新增NestedMapTypeHandler处理嵌套Map与JSON互转 - 修改VideoReview相关实体类和DTO以支持嵌套Map结构 - 更新数据库查询逻辑以适配新的评价数据结构 - 优化平均分计算方法以处理多机位多维度评分 - 完善MyBatis配置中的typeHandler引用 - 补充视频查询接口返回任务开始结束时间字段 - 修正SQL关联查询条件确保数据准确性
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package com.ycwl.basic.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 嵌套Map类型的TypeHandler,用于处理JSON字段与Map<String, Map<String, Integer>>的互转
|
||||
* 主要用于机位评价功能:外层key为机位ID,内层Map为该机位的各维度评分
|
||||
*
|
||||
* 数据格式示例:
|
||||
* {
|
||||
* "12345": {"清晰度": 5, "构图": 4, "色彩": 5, "整体效果": 4},
|
||||
* "12346": {"清晰度": 4, "构图": 5, "色彩": 4, "整体效果": 5}
|
||||
* }
|
||||
*/
|
||||
@Slf4j
|
||||
public class NestedMapTypeHandler extends BaseTypeHandler<Map<String, Map<String, Integer>>> {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private final TypeReference<Map<String, Map<String, Integer>>> typeReference =
|
||||
new TypeReference<Map<String, Map<String, Integer>>>() {};
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, Map<String, Map<String, Integer>> parameter, JdbcType jdbcType) throws SQLException {
|
||||
try {
|
||||
String json = objectMapper.writeValueAsString(parameter);
|
||||
ps.setString(i, json);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("序列化嵌套Map为JSON失败", e);
|
||||
throw new SQLException("序列化嵌套Map为JSON失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, Integer>> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String json = rs.getString(columnName);
|
||||
return parseJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, Integer>> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String json = rs.getString(columnIndex);
|
||||
return parseJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, Integer>> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String json = cs.getString(columnIndex);
|
||||
return parseJson(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析JSON字符串为嵌套Map
|
||||
*/
|
||||
private Map<String, Map<String, Integer>> parseJson(String json) {
|
||||
if (json == null || json.trim().isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
try {
|
||||
return objectMapper.readValue(json, typeReference);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("解析JSON为嵌套Map失败, json={}", json, e);
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user