Commit 3bac9d07 by zhangxingmin

Merge remote-tracking branch 'origin/dev' into prod

parents 642f8f53 da8eadbc
......@@ -15,6 +15,10 @@ import com.yd.oss.feign.request.ApiRelObjectMaterialUploadSubmitRequest;
import com.yd.oss.feign.response.ApiRelObjectMaterialPageResponse;
import com.yd.oss.service.model.RelObjectMaterial;
import com.yd.oss.service.service.IRelObjectMaterialService;
import com.yd.user.feign.client.sysdict.ApiSysDictFeignClient;
import com.yd.user.feign.request.sysdict.GetDictTypeListRequest;
import com.yd.user.feign.response.sysdict.GetDictItemListByDictTypeResponse;
import com.yd.user.feign.response.sysdict.GetDictTypeListResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -22,8 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -36,6 +39,9 @@ public class ApiRelObjectMaterialServiceImpl implements ApiRelObjectMaterialServ
@Autowired
private ApiOssFileService apiOssFileService;
@Autowired
private ApiSysDictFeignClient apiSysDictFeignClient;
/**
* 分页列表查询-对象材料关系表信息
* @param request
......@@ -45,6 +51,71 @@ public class ApiRelObjectMaterialServiceImpl implements ApiRelObjectMaterialServ
public Result<IPage<ApiRelObjectMaterialPageResponse>> page(ApiRelObjectMaterialPageRequest request) {
Page<ApiRelObjectMaterialPageResponse> page = new Page<>(request.getPageNo(), request.getPageSize());
IPage<ApiRelObjectMaterialPageResponse> iPage = iRelObjectMaterialService.page(page, request);
// 如果没有数据,直接返回
if (iPage == null || CollectionUtils.isEmpty(iPage.getRecords())) {
return Result.success(iPage);
}
// 收集需要翻译的字典编码
Set<String> dataPersonSet = new HashSet<>();
Set<String> dataTypeSet = new HashSet<>();
for (ApiRelObjectMaterialPageResponse record : iPage.getRecords()) {
if (record.getDataPerson() != null) {
dataPersonSet.add(record.getDataPerson());
}
if (record.getDataType() != null) {
dataTypeSet.add(record.getDataType());
}
}
// 构建字典类型列表,批量查询
List<String> dictTypes = new ArrayList<>();
dictTypes.add("oss_data_person");
dictTypes.add("oss_data_type");
GetDictTypeListRequest dictRequest = new GetDictTypeListRequest();
dictRequest.setTypeList(dictTypes);
Result<List<GetDictTypeListResponse>> dictResult = apiSysDictFeignClient.getByDictTypeList(dictRequest);
if (dictResult == null || dictResult.getCode() !=200 || CollectionUtils.isEmpty(dictResult.getData())) {
log.warn("字典查询失败,无法翻译名称");
return Result.success(iPage);
}
// 构建字典映射:dictType -> (itemValue -> itemLabel)
Map<String, Map<String, String>> dictMapping = new HashMap<>();
for (GetDictTypeListResponse dictTypeResp : dictResult.getData()) {
String dictType = dictTypeResp.getDictType();
List<GetDictItemListByDictTypeResponse> itemList = dictTypeResp.getDictItemList();
if (CollectionUtils.isEmpty(itemList)) {
continue;
}
Map<String, String> valueToLabel = itemList.stream()
.filter(item -> item.getStatus() == 1) // 只取启用状态
.collect(Collectors.toMap(
GetDictItemListByDictTypeResponse::getItemValue,
GetDictItemListByDictTypeResponse::getItemLabel,
(existing, replacement) -> existing
));
dictMapping.put(dictType, valueToLabel);
}
// 获取两个字典的映射
Map<String, String> personMap = dictMapping.getOrDefault("oss_data_person", Collections.emptyMap());
Map<String, String> typeMap = dictMapping.getOrDefault("oss_data_type", Collections.emptyMap());
// 填充名称
for (ApiRelObjectMaterialPageResponse record : iPage.getRecords()) {
String dataPerson = record.getDataPerson();
if (dataPerson != null) {
record.setDataPersonName(personMap.get(dataPerson));
}
String dataType = record.getDataType();
if (dataType != null) {
record.setDataTypeName(typeMap.get(dataType));
}
}
return Result.success(iPage);
}
......
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;
import com.yd.oss.feign.dto.OssFileInfo;
import lombok.Data;
import java.util.List;
......@@ -32,11 +33,21 @@ public class ApiRelObjectMaterialPageResponse {
private String dataPerson;
/**
* 资料人(字典)名称
*/
private String dataPersonName;
/**
* 资料类型(字典)
*/
private String dataType;
/**
* 资料类型(字典)名称
*/
private String dataTypeName;
/**
* 注意事项
*/
private String precautions;
......@@ -44,6 +55,6 @@ public class ApiRelObjectMaterialPageResponse {
/**
* 文件URL列表(完整路径)
*/
private List<String> fileUrlList;
private List<OssFileInfo> fileUrlList;
}
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.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@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
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i, String.join(";", parameter));
public void setNonNullParameter(PreparedStatement ps, int i, List<OssFileInfo> parameter, JdbcType jdbcType) throws SQLException {
try {
ps.setString(i, objectMapper.writeValueAsString(parameter));
} catch (JsonProcessingException e) {
throw new SQLException(e);
}
}
@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);
return convertStringToList(value);
return parseJsonArray(value);
}
@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);
return convertStringToList(value);
return parseJsonArray(value);
}
@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);
return convertStringToList(value);
return parseJsonArray(value);
}
private List<String> convertStringToList(String value) {
private List<OssFileInfo> parseJsonArray(String value) {
if (value == null || value.trim().isEmpty()) {
return Collections.emptyList();
}
return Arrays.stream(value.split(";"))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
try {
return objectMapper.readValue(value, new TypeReference<List<OssFileInfo>>() {});
} catch (JsonProcessingException e) {
return Collections.emptyList();
}
}
}
\ No newline at end of file
......@@ -11,8 +11,8 @@
<result property="dataType" column="data_type"/>
<result property="precautions" column="precautions"/>
<!-- 使用类型处理器将分号分隔的字符串转换为List -->
<result property="fileUrlList" column="file_urls"
typeHandler="com.yd.oss.service.handler.StringToListTypeHandler"/>
<result property="fileUrlList" column="file_infos"
typeHandler="com.yd.oss.service.handler.JsonToListTypeHandler"/>
</resultMap>
<select id="page" resultMap="RelObjectMaterialResponseMap">
......@@ -24,10 +24,20 @@
m.data_person,
m.data_type,
m.precautions,
CONCAT(
'[',
GROUP_CONCAT(
CONCAT('https://', f.bucket_name, '.', p.endpoint, '/', f.file_key)
SEPARATOR ';'
) as file_urls
IF(f.id IS NOT NULL,
JSON_OBJECT(
'fileUrl', CONCAT('https://', f.bucket_name, '.', p.endpoint, '/', f.file_key),
'fileName', f.original_name
),
NULL
)
SEPARATOR ','
),
']'
) as file_infos
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 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