res.nsuFlag = facClient.getFlagNSU();
res.regBegin = facClient.getRegBegin();
res.regEnd = facClient.getRegEnd();
FacilityDocument doc = null;
List<FacilityDocument> docList =
findEntityList(FacilityDocument.class, new Field[]{new Field("snils", facClient.getSnils())});
if (docList.isEmpty()) {
return res;
}
Collections.sort(docList, new Comparator<FacilityDocument>() {
@Override
public int compare(FacilityDocument o1, FacilityDocument o2) {
if (o1.getGspEnd()==null) {
return 1;
}
if (o2.getGspEnd()==null) {
return -1;
}
return o1.getGspEnd().compareTo(o2.getGspEnd());
}
});
for (int i = 0; i < docList.size(); i++) {
doc = docList.get(i);
if (doc.getExcemption() != null) {
int ex = doc.getExcemption().getId();
if ((!both && ex == res.exempId)
|| (both && (ex == ex1 || ex == ex2))
|| (ex1 + ex2 == 0)) {
res.docName = doc.getDocumentName();
res.docSN = doc.getDocumentSN();
res.gspBegin = doc.getGspBegin();
res.gspEnd = doc.getGspEnd();
res.exempId = ex;
}
}
}