mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
opt queryDictValue (#1787)
This commit is contained in:
@@ -16,4 +16,6 @@ public class DimValueMap {
|
||||
|
||||
/** dimension value for user query */
|
||||
private List<String> alias = new ArrayList<>();
|
||||
|
||||
private String value;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
@Data
|
||||
@ToString
|
||||
public class DictValueDimResp extends DictValueResp {
|
||||
/** dimension value for result show */
|
||||
/** dimension value */
|
||||
private String bizName;
|
||||
|
||||
/** dimension value for user query */
|
||||
|
||||
@@ -28,9 +28,6 @@ import java.util.stream.Stream;
|
||||
@Component
|
||||
public class FileHandlerImpl implements FileHandler {
|
||||
|
||||
@Value("${dict.value.max.count.page:1000}")
|
||||
private int dictValueMaxCountPage;
|
||||
|
||||
public static final String FILE_SPILT = File.separator;
|
||||
|
||||
private final LocalFileConfig localFileConfig;
|
||||
@@ -124,8 +121,8 @@ public class FileHandlerImpl implements FileHandler {
|
||||
DictValueReq dictValueReq) {
|
||||
PageInfo<DictValueResp> dictValueRespPageInfo = new PageInfo<>();
|
||||
String filePath = localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName;
|
||||
Long fileLineNum = Math.min(dictValueMaxCountPage, getFileLineNum(filePath));
|
||||
Integer startLine = 1;
|
||||
Long fileLineNum = getFileLineNum(filePath);
|
||||
Integer startLine = Math.max(1, (dictValueReq.getCurrent() - 1) * dictValueReq.getPageSize() + 1);
|
||||
Integer endLine = Integer.valueOf(
|
||||
Math.min(dictValueReq.getCurrent() * dictValueReq.getPageSize(), fileLineNum) + "");
|
||||
List<DictValueResp> dictValueRespList = getFileData(filePath, startLine, endLine);
|
||||
@@ -135,7 +132,7 @@ public class FileHandlerImpl implements FileHandler {
|
||||
dictValueRespPageInfo.setTotal(fileLineNum);
|
||||
dictValueRespPageInfo.setList(dictValueRespList);
|
||||
dictValueRespPageInfo.setHasNextPage(endLine >= fileLineNum ? false : true);
|
||||
dictValueRespPageInfo.setHasPreviousPage(startLine <= 0 ? false : true);
|
||||
dictValueRespPageInfo.setHasPreviousPage(startLine <= 1 ? false : true);
|
||||
return dictValueRespPageInfo;
|
||||
}
|
||||
|
||||
@@ -149,6 +146,13 @@ public class FileHandlerImpl implements FileHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filePath
|
||||
* @param startLine 1开始
|
||||
* @param endLine
|
||||
* @return
|
||||
*/
|
||||
private List<DictValueResp> getFileData(String filePath, Integer startLine, Integer endLine) {
|
||||
List<DictValueResp> fileData = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -178,9 +178,28 @@ public class DictTaskServiceImpl implements DictTaskService {
|
||||
PageInfo<DictValueResp> dictValueRespList =
|
||||
fileHandler.queryDictValue(fileName, dictValueReq);
|
||||
PageInfo<DictValueDimResp> result = convert2DictValueDimRespPage(dictValueRespList);
|
||||
fillDimMapInfo(result.getList(), dictValueReq.getItemId());
|
||||
return result;
|
||||
}
|
||||
|
||||
private void fillDimMapInfo(List<DictValueDimResp> list, Long dimId) {
|
||||
DimensionResp dimResp = dimensionService.getDimension(dimId);
|
||||
if (CollectionUtils.isEmpty(dimResp.getDimValueMaps())) {
|
||||
return;
|
||||
}
|
||||
Map<String, DimValueMap> valueAndMap = dimResp.getDimValueMaps().stream()
|
||||
.collect(Collectors.toMap(dim -> dim.getValue(), v -> v, (v1, v2) -> v2));
|
||||
if (CollectionUtils.isEmpty(valueAndMap)) {
|
||||
return;
|
||||
}
|
||||
list.stream().forEach(dictValueDimResp -> {
|
||||
String dimValue = dictValueDimResp.getValue();
|
||||
if (valueAndMap.containsKey(dimValue) && Objects.nonNull(valueAndMap.get(dimValue))) {
|
||||
dictValueDimResp.setAlias(valueAndMap.get(dimValue).getAlias());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PageInfo<DictValueDimResp> convert2DictValueDimRespPage(
|
||||
PageInfo<DictValueResp> dictValueRespPage) {
|
||||
PageInfo<DictValueDimResp> result = new PageInfo<>();
|
||||
|
||||
@@ -34,6 +34,11 @@ public class DimensionConverter {
|
||||
dimensionDO.setDefaultValues(JSONObject.toJSONString(dimensionReq.getDefaultValues()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dimensionReq.getDimValueMaps())) {
|
||||
List<DimValueMap> dimValueMaps = dimensionReq.getDimValueMaps();
|
||||
dimValueMaps.stream().forEach(dimValueMap -> {
|
||||
dimValueMap.setTechName(dimValueMap.getValue());
|
||||
});
|
||||
|
||||
dimensionDO.setDimValueMaps(JSONObject.toJSONString(dimensionReq.getDimValueMaps()));
|
||||
} else {
|
||||
dimensionDO.setDimValueMaps(JSONObject.toJSONString(new ArrayList<>()));
|
||||
|
||||
Reference in New Issue
Block a user