Date current = GregorianCalendar.getInstance().getTime();
if (canWork) {
List<Client> clients = getDao().getList(queryCriteria, 0, 51);
List<ClientLine> lines = new ArrayList<ClientLine>();
for (Client client : clients) {
Address address = null;
if (client.getAddressID() != null) {
address = getDao().getById(Address.class, client.getAddressID());
}
if (address != null && dto.getHouse() != null && !dto.getHouse().isEmpty()) {
if (address.getBuilding() == null || !address.getBuilding().equals(dto.getHouse())) {
continue;
}
}
if (address != null && dto.getFlat() != null && !dto.getFlat().isEmpty()) {
if (address.getFlat() == null || !address.getFlat().equals(dto.getFlat())) {
continue;
}
}
if (address != null && dto.getCity() != null && !dto.getCity().isEmpty()) {
//Фильтруем по району/нас пункту
AddressObject item = address.getAddressObject();
boolean founded = false;
while (item != null) {
if ((item.getType().getLevel() == 3 || item.getType().getLevel() == 4)
&& item.getTitle().toUpperCase().startsWith(dto.getCity().toUpperCase())) {
founded = true;
}
item = item.getParent();
}
if (!founded) {
continue;
}
}
if (address != null && dto.getStreet() != null && !dto.getStreet().isEmpty()) {
//Фильтруем по улице
AddressObject item = address.getAddressObject();
boolean founded = false;
while (item != null) {
if (item.getType().getLevel() == 5
&& item.getTitle().toUpperCase().startsWith(dto.getStreet().toUpperCase())) {
founded = true;
}
item = item.getParent();
}
if (!founded) {
continue;
}
}
ClientLine cl = new ClientLine();
cl.client = client;
cl.date = Converter.dateToString(client.getBorn());
if (client.getBorn() != null) {
cl.age = Integer.toString(DateTimeUtils.calcAge(client.getBorn(), current));
} else {
cl.age = "";
}
cl.addressStr = address == null ? "" : address.getAsStringShort();
cl.lpu = client.getDistrict() == null ? "" : client.getDistrict().getLpu().getTitleShort();
lines.add(cl);
}
model.put("lines", lines);
model.put("linescount", lines.size());