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