85 lines
2.9 KiB
Java
85 lines
2.9 KiB
Java
package ru.nbch.indicsearchservice.util;
|
|
|
|
import java.sql.Date;
|
|
import java.sql.Timestamp;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import org.springframework.stereotype.Component;
|
|
import ru.nbch.indicsearchservice.model.TableData;
|
|
import ru.nbch.indicsearchservice.model.enums.DataType;
|
|
import ru.nbch.indicsearchservice.model.enums.SearchParameter;
|
|
|
|
@Component
|
|
public class IndicSearchUtils {
|
|
public Set<Integer> getFidsBasedOnDataTypeAndSearchParameter(DataType dataType, SearchParameter searchParameter, String searchValue) {
|
|
Set<Integer> fids = new HashSet<>();
|
|
|
|
if (dataType == null || searchParameter == null) {
|
|
return fids;
|
|
}
|
|
|
|
if (dataType == DataType.GUTDF || dataType == DataType.RUTDF) {
|
|
if (searchParameter == SearchParameter.FID) {
|
|
return Set.of(Integer.parseInt(searchValue));
|
|
}
|
|
} else if (dataType == DataType.TUTDF) {
|
|
if (searchParameter == SearchParameter.FID) {
|
|
return Set.of(Integer.parseInt(searchValue));
|
|
}
|
|
}
|
|
|
|
return fids;
|
|
}
|
|
|
|
public TableData mapToTableData(String table, Map<String, Object> row) {
|
|
List<TableData.FieldData> fields = row.entrySet().stream()
|
|
.map(e -> new TableData.FieldData(e.getKey(), parseTableValue(e.getValue())))
|
|
.toList();
|
|
|
|
return new TableData(table, fields);
|
|
}
|
|
|
|
private Object parseTableValue(Object value) {
|
|
return switch (value) {
|
|
case Timestamp timestamp ->
|
|
timestamp.toLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
case Date date -> {
|
|
LocalDate localDate = date.toLocalDate();
|
|
if (localDate.equals(Date.valueOf("0001-01-01").toLocalDate()) ||
|
|
localDate.equals(Date.valueOf("0001-01-03").toLocalDate())) {
|
|
yield null;
|
|
}
|
|
yield localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
}
|
|
case Integer i -> {
|
|
if (i == Integer.MAX_VALUE) {
|
|
yield null;
|
|
}
|
|
yield i;
|
|
}
|
|
case Long l -> {
|
|
if (l == Long.MAX_VALUE) {
|
|
yield null;
|
|
}
|
|
yield l;
|
|
}
|
|
case null -> null;
|
|
default -> value;
|
|
};
|
|
}
|
|
|
|
public List<TableData> getFirstLevelTables(Map<String, List<TableData>> tableDataMapByFid) {
|
|
List<TableData> result = new ArrayList<>();
|
|
|
|
for (Map.Entry<String, List<TableData>> entry : tableDataMapByFid.entrySet()) {
|
|
if (entry.getKey().equals("RU_UID")) {}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|