use of com.orion.ops.dao.MachineSecretKeyDAO in project orion-ops by lijiahangmax.
the class MachineKeyServiceImpl method listKeys.
@Override
public DataGrid<MachineSecretKeyVO> listKeys(MachineKeyRequest request) {
final int page = request.getPage();
final int limit = request.getLimit();
final boolean checkStatus = request.getMountStatus() != null;
if (checkStatus) {
request.setPage(Const.N_1);
request.setLimit(Const.N_100000);
}
LambdaQueryWrapper<MachineSecretKeyDO> wrapper = new LambdaQueryWrapper<MachineSecretKeyDO>().like(Strings.isNotBlank(request.getName()), MachineSecretKeyDO::getKeyName, request.getName()).like(Strings.isNotBlank(request.getDescription()), MachineSecretKeyDO::getDescription, request.getDescription()).orderByDesc(MachineSecretKeyDO::getCreateTime);
DataGrid<MachineSecretKeyVO> dataGrid = DataQuery.of(machineSecretKeyDAO).page(request).wrapper(wrapper).dataGrid(MachineSecretKeyVO.class);
if (!dataGrid.isEmpty()) {
List<String> loadKeys = SessionHolder.getLoadKeys();
for (MachineSecretKeyVO row : dataGrid.getRows()) {
String path = row.getPath();
boolean isFile = Files1.isFile(new File(MachineKeyService.getKeyPath(path)));
if (isFile) {
boolean match = loadKeys.stream().anyMatch(key -> key.endsWith(path));
if (match) {
row.setMountStatus(MountKeyStatus.MOUNTED.getStatus());
} else {
row.setMountStatus(MountKeyStatus.DUMPED.getStatus());
}
} else {
row.setMountStatus(MountKeyStatus.NOT_FOUND.getStatus());
}
}
}
if (!checkStatus) {
return dataGrid;
} else {
// 手动过滤
List<MachineSecretKeyVO> totalRows = dataGrid.stream().filter(row -> request.getMountStatus().equals(row.getMountStatus())).collect(Collectors.toList());
List<MachineSecretKeyVO> rows = new LimitList<>(totalRows, limit).page(page);
// 封装返回
DataGrid<MachineSecretKeyVO> newDataGrid = DataGrid.of(rows, totalRows.size());
newDataGrid.setPage(page);
newDataGrid.setLimit(limit);
return newDataGrid;
}
}
Aggregations