(improvement)(knowledge) add keyValue parameter for queryDictValue (#1749)

This commit is contained in:
daikon
2024-10-08 00:10:34 +08:00
committed by GitHub
parent ff709aec60
commit ee6b8a1044
8 changed files with 186 additions and 9 deletions

View File

@@ -77,10 +77,51 @@ public class FileHandlerImpl implements FileHandler {
@Override
public PageInfo<DictValueResp> queryDictValue(String fileName, DictValueReq dictValueReq) {
if (StringUtils.isEmpty(dictValueReq.getKeyValue())) {
return getDictValueRespPagWithoutKey(fileName, dictValueReq);
}
return getDictValueRespPagWithKey(fileName, dictValueReq);
}
private PageInfo<DictValueResp> getDictValueRespPagWithKey(String fileName,
DictValueReq dictValueReq) {
PageInfo<DictValueResp> dictValueRespPageInfo = new PageInfo<>();
dictValueRespPageInfo.setPageSize(dictValueReq.getPageSize());
dictValueRespPageInfo.setPageNum(dictValueReq.getCurrent());
String filePath = localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName;
Long fileLineNum = getFileLineNum(filePath);
Integer startLine = 1;
List<DictValueResp> dictValueRespList =
getFileData(filePath, startLine, fileLineNum.intValue());
dictValueRespList = dictValueRespList.stream()
.filter(dictValue -> dictValue.getValue().contains(dictValueReq.getKeyValue()))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(dictValueRespList)) {
dictValueRespPageInfo.setList(new ArrayList<>());
return dictValueRespPageInfo;
}
Integer startIndex =
Math.max((dictValueReq.getCurrent() - 1) * dictValueReq.getPageSize(), 0);
Integer endIndex =
Integer.valueOf(Math.min(dictValueReq.getCurrent() * dictValueReq.getPageSize(),
dictValueRespList.size()) + "");
List<DictValueResp> list = dictValueRespList.subList(startIndex, endIndex);
dictValueRespPageInfo.setPageSize(dictValueReq.getPageSize());
dictValueRespPageInfo.setPageNum(dictValueReq.getCurrent());
dictValueRespPageInfo.setTotal(dictValueRespList.size());
dictValueRespPageInfo.setList(list);
dictValueRespPageInfo.setHasNextPage(endIndex >= dictValueRespList.size() ? false : true);
dictValueRespPageInfo.setHasPreviousPage(startLine <= 0 ? false : true);
return dictValueRespPageInfo;
}
private PageInfo<DictValueResp> getDictValueRespPagWithoutKey(String fileName,
DictValueReq dictValueReq) {
PageInfo<DictValueResp> dictValueRespPageInfo = new PageInfo<>();
String filePath = localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName;
Long fileLineNum = getFileLineNum(filePath);
Integer startLine = (dictValueReq.getCurrent() - 1) * dictValueReq.getPageSize() + 1;
Integer startLine = 1;
Integer endLine = Integer.valueOf(
Math.min(dictValueReq.getCurrent() * dictValueReq.getPageSize(), fileLineNum) + "");
List<DictValueResp> dictValueRespList = getFileData(filePath, startLine, endLine);