Commit 4d153134 by zhangxingmin

push

parent 93314088
package com.yd.oss.feign.dto;
import lombok.Data;
@Data
public class OssFileInfo {
private String fileUrl;
private String fileName;
}
\ No newline at end of file
package com.yd.oss.feign.response; package com.yd.oss.feign.response;
import com.yd.oss.feign.dto.OssFileInfo;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
...@@ -44,6 +45,6 @@ public class ApiRelObjectMaterialPageResponse { ...@@ -44,6 +45,6 @@ public class ApiRelObjectMaterialPageResponse {
/** /**
* 文件URL列表(完整路径) * 文件URL列表(完整路径)
*/ */
private List<String> fileUrlList; private List<OssFileInfo> fileUrlList;
} }
package com.yd.oss.service.handler; package com.yd.oss.service.handler;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yd.oss.feign.dto.OssFileInfo;
import org.apache.ibatis.type.BaseTypeHandler; import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes; import org.apache.ibatis.type.MappedTypes;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@MappedTypes(List.class) @MappedTypes(List.class)
public class StringToListTypeHandler extends BaseTypeHandler<List<String>> { public class JsonToListTypeHandler extends BaseTypeHandler<List<OssFileInfo>> {
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override @Override
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException { public void setNonNullParameter(PreparedStatement ps, int i, List<OssFileInfo> parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i, String.join(";", parameter)); try {
ps.setString(i, objectMapper.writeValueAsString(parameter));
} catch (JsonProcessingException e) {
throw new SQLException(e);
}
} }
@Override @Override
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException { public List<OssFileInfo> getNullableResult(ResultSet rs, String columnName) throws SQLException {
String value = rs.getString(columnName); String value = rs.getString(columnName);
return convertStringToList(value); return parseJsonArray(value);
} }
@Override @Override
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException { public List<OssFileInfo> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String value = rs.getString(columnIndex); String value = rs.getString(columnIndex);
return convertStringToList(value); return parseJsonArray(value);
} }
@Override @Override
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { public List<OssFileInfo> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String value = cs.getString(columnIndex); String value = cs.getString(columnIndex);
return convertStringToList(value); return parseJsonArray(value);
} }
private List<String> convertStringToList(String value) { private List<OssFileInfo> parseJsonArray(String value) {
if (value == null || value.trim().isEmpty()) { if (value == null || value.trim().isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
return Arrays.stream(value.split(";")) try {
.map(String::trim) return objectMapper.readValue(value, new TypeReference<List<OssFileInfo>>() {});
.filter(s -> !s.isEmpty()) } catch (JsonProcessingException e) {
.collect(Collectors.toList()); return Collections.emptyList();
}
} }
} }
\ No newline at end of file
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
<result property="dataType" column="data_type"/> <result property="dataType" column="data_type"/>
<result property="precautions" column="precautions"/> <result property="precautions" column="precautions"/>
<!-- 使用类型处理器将分号分隔的字符串转换为List --> <!-- 使用类型处理器将分号分隔的字符串转换为List -->
<result property="fileUrlList" column="file_urls" <result property="fileUrlList" column="file_infos"
typeHandler="com.yd.oss.service.handler.StringToListTypeHandler"/> typeHandler="com.yd.oss.service.handler.JsonToListTypeHandler"/>
</resultMap> </resultMap>
<select id="page" resultMap="RelObjectMaterialResponseMap"> <select id="page" resultMap="RelObjectMaterialResponseMap">
...@@ -25,9 +25,12 @@ ...@@ -25,9 +25,12 @@
m.data_type, m.data_type,
m.precautions, m.precautions,
GROUP_CONCAT( GROUP_CONCAT(
CONCAT('https://', f.bucket_name, '.', p.endpoint, '/', f.file_key) JSON_OBJECT(
'fileUrl', CONCAT('https://', f.bucket_name, '.', p.endpoint, '/', f.file_key),
'fileName', f.original_name
)
SEPARATOR ';' SEPARATOR ';'
) as file_urls ) as file_infos
FROM rel_object_material rom FROM rel_object_material rom
LEFT JOIN material m ON m.material_biz_id = rom.material_biz_id AND m.is_deleted = 0 LEFT JOIN material m ON m.material_biz_id = rom.material_biz_id AND m.is_deleted = 0
LEFT JOIN oss_file f ON f.object_biz_id = rom.rel_object_material_biz_id LEFT JOIN oss_file f ON f.object_biz_id = rom.rel_object_material_biz_id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment