Как добавить id из метода в фильтер
Необходимо добавить id из метода queryBaseCheck в метод getJRDataSource в filter. Пробовал через стримы но по логам возвращается null вместо id.
@Override
public JRDataSource getJRDataSource(Connection connection, Map<String, Object> params) throws Exception {
final Date periodStart = (Date) params.get(DIALOG_PERIOD_START);
final Date periodEnd = (Date) params.get(DIALOG_PERIOD_END);
final Id sp = (Id) params.get(DIALOG_SP);
final Id go = (Id) params.get(DIALOG_GO);
final String documentType = (String) params.get(DIALOG_TYPE);
// List<String> idResult = queryBaseCheck(sp, periodEnd, periodStart, documentType);
final List<Value<?>> filter = new ArrayList<>();
filter.add(new DateTimeValue(periodStart));
filter.add(new DateTimeValue(periodEnd));
filter.add(new ReferenceValue(sp));
if (go != null ) {
filter.add(new ReferenceValue(go));
}
filter.add(new StringValue(documentType));
List<ReportRowCheck>reportRowCheckList=queryBaseCheck(filter);
for (ReportRowCheck reportRowCheck:reportRowCheckList){
filter.add(new StringValue(reportRowCheck.getId()));
}
log.error("filter: {}", filter);
final List<ReportRow> result = new ArrayList<>(queryBase(filter));
return new JRBeanCollectionDataSource(result);
}
private List<ReportRow> queryBase(final List<Value<?>> filter) {
final List<ReportRow> result = new ArrayList<>();
final boolean sessionAlreadyOpened = AFSession.isDefinedOrOpened();
if (!sessionAlreadyOpened) {
AFSession.Manual.defineLocalUser();
}
// получаем коллекцию по sql-запросу
IdentifiableObjectCollection collection = collectionService.findCollectionByQuery(QUERY_BASE, filter);
log.error("QUERY_BASE fil:{}", filter);
for (IdentifiableObject o : collection) {
ReportRow reportRow = new ReportRow();
log.error("o.classQ: {}", o.getClass());
log.error("oQR: {}", o);
reportRow.setIdrkk(o.getReference(IDRKK));
reportRow.setRkktype(o.getString(RKKTYPE));
reportRow.setSubject(o.getString(SUBJECT));
reportRow.setLifecycle(o.getString(LIFECYCLE));
result.add(reportRow);
}
if (!sessionAlreadyOpened) {
close();
}
return result;
}
public static class ReportRow {
private Object idrkk;
private String rkktype;
private String subject;
private String lifecycle;
public Object getIdrkk() {
return idrkk;
}
public String getRkktype() {
return rkktype;
}
public String getSubject() {
return subject;
}
public String getLifecycle() {
return lifecycle;
}
public void setIdrkk(Object idrkk) {
this.idrkk = idrkk;
}
public void setRkktype(String rkktype) {
this.rkktype = rkktype;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setLifecycle(String lifecycle) {
this.lifecycle = lifecycle;
}
}
private List<ReportRowCheck> queryBaseCheck(final List<Value<?>> filter) {
final List<ReportRowCheck> results = new ArrayList<>();
log.error("QUERY_BASE_C fils:{}", filter);
Map<String, Map<String, Integer>> resultMap = new HashMap<String, Map<String, Integer>>();
final boolean sessionAlreadyOpened = AFSession.isDefinedOrOpened();
if (!sessionAlreadyOpened) {
AFSession.Manual.defineLocalUser();
}
IdentifiableObjectCollection collection = collectionService.findCollectionByQuery(QUERY_BASE_CHECK, filter);
for (IdentifiableObject o : collection) {
Map<String, Integer> tmpMap = new HashMap<String, Integer>();
String unidAndStage = o.getString("unidVisa");
String id = "";
Id idanswer = o.getReference("id");
if (isBeginStage(unidAndStage)) {
id += ((RdbmsId) idanswer).getId();
log.error("QUERY_BASE_CHECK:{}", filter);
log.error("o.class: {}", o.getClass());
log.error("oCH: {}", o);
String depparty = o.getString(DEPPARTY);
String answer = o.getString("answer");
AFDate dateVisa = null;
Integer allnoVisa = 0;
Integer allyesVisa = 0;
Integer allinterm = 0;
Integer yesinterm = 0;
Integer specinterm = 0;
Integer nointerm = 0;
Integer allex = 0;
Integer yesex = 0;
Integer specex = 0;
Integer noex = 0;
Integer procent = 0;
if ("".equals(answer)) {
allnoVisa++;
} else {
allyesVisa++;
}
TimelessDate timevisa = o.getTimelessDate("timevisa");
if (timevisa != null) {
dateVisa = AFDate.fromJavaDate(timevisa.toDate(), false);
}
AFDate dueDate = getDueDateForStage(unidAndStage);
if (dateVisa != null && dueDate != null && dateVisa.compareTo(dueDate) <= 0) {
allinterm++;
if ("1".equals(answer)) {
yesinterm++;
} else if ("2".equals(answer)) {
nointerm++;
} else if ("3".equals(answer)) {
specinterm++;
}
} else if (dateVisa != null && dueDate != null && dateVisa.compareTo(dueDate) > 0) {
allex++;
if ("1".equals(answer)) {
yesex++;
} else if ("2".equals(answer)) {
noex++;
} else if ("3".equals(answer)) {
specex++;
}
}
if (resultMap.containsKey(depparty)) {
tmpMap = resultMap.get(depparty);
tmpMap.put(ALLNOVISA, tmpMap.get(ALLNOVISA) + allnoVisa);
tmpMap.put(ALLYESVISA, tmpMap.get(ALLYESVISA) + allyesVisa);
tmpMap.put(ALLINTERM, tmpMap.get(ALLINTERM) + allinterm);
tmpMap.put(YESINTERM, tmpMap.get(YESINTERM) + yesinterm);
tmpMap.put(SPECINTERM, tmpMap.get(SPECINTERM) + specinterm);
tmpMap.put(NOINTERM, tmpMap.get(NOINTERM) + nointerm);
tmpMap.put(ALLEX, tmpMap.get(ALLEX) + allex);
tmpMap.put(YESEX, tmpMap.get(YESEX) + yesex);
tmpMap.put(SPECEX, tmpMap.get(SPECEX) + specex);
tmpMap.put(NOEX, tmpMap.get(NOEX) + noex);
} else {
tmpMap.put(ALLNOVISA, allnoVisa);
tmpMap.put(ALLYESVISA, allyesVisa);
tmpMap.put(ALLINTERM, allinterm);
tmpMap.put(YESINTERM, yesinterm);
tmpMap.put(SPECINTERM, specinterm);
tmpMap.put(NOINTERM, nointerm);
tmpMap.put(ALLEX, allex);
tmpMap.put(YESEX, yesex);
tmpMap.put(SPECEX, specex);
tmpMap.put(NOEX, noex);
}
resultMap.put(depparty, tmpMap);
}
}
Integer allnovisa = 0;
Integer allyesvisa = 0;
Integer allinterm = 0;
Integer yesinterm = 0;
Integer specinterm = 0;
Integer nointerm = 0;
Integer allex = 0;
Integer yesex = 0;
Integer specex = 0;
Integer noex = 0;
Integer procent = 0;
resultMap = new TreeMap<String, Map<String, Integer>>(resultMap);
for (Map.Entry<String, Map<String, Integer>> entry : resultMap.entrySet()) {
ReportRowCheck reportRowCheck = new ReportRowCheck();
reportRowCheck.setDepparty(entry.getKey());
Map<String, Integer> mapValue = entry.getValue();
allnovisa = allnovisa + mapValue.get(ALLNOVISA);
allyesvisa = allyesvisa + mapValue.get(ALLYESVISA);
allinterm = allinterm + mapValue.get(ALLINTERM);
yesinterm = yesinterm + mapValue.get(YESINTERM);
specinterm = specinterm + mapValue.get(SPECINTERM);
nointerm = nointerm + mapValue.get(NOINTERM);
allex = allex + mapValue.get(ALLEX);
yesex = yesex + mapValue.get(YESEX);
specex = specex + mapValue.get(SPECEX);
noex = noex + mapValue.get(NOEX);
reportRowCheck.setAllnoVisa(Integer.toString(mapValue.get(ALLNOVISA)));
reportRowCheck.setAllyesVisa(Integer.toString(mapValue.get(ALLYESVISA)));
reportRowCheck.setAllinterm(Integer.toString(mapValue.get(ALLINTERM)));
reportRowCheck.setYesinterm(Integer.toString(mapValue.get(YESINTERM)));
reportRowCheck.setSpecinterm(Integer.toString(mapValue.get(SPECINTERM)));
reportRowCheck.setNointerm(Integer.toString(mapValue.get(NOINTERM)));
reportRowCheck.setAllex(Integer.toString(mapValue.get(ALLEX)));
reportRowCheck.setYesex(Integer.toString(mapValue.get(YESEX)));
reportRowCheck.setSpecex(Integer.toString(mapValue.get(SPECEX)));
reportRowCheck.setNoex(Integer.toString(mapValue.get(NOEX)));
results.add(reportRowCheck);
}
ReportRowCheck reportRowCheck = new ReportRowCheck();
reportRowCheck.setDepparty("ИТОГО:");
reportRowCheck.setAllnoVisa(Integer.toString(allnovisa));
reportRowCheck.setAllyesVisa(Integer.toString(allyesvisa));
reportRowCheck.setAllinterm(Integer.toString(allinterm));
reportRowCheck.setYesinterm(Integer.toString(yesinterm));
reportRowCheck.setSpecinterm(Integer.toString(specinterm));
reportRowCheck.setNointerm(Integer.toString(nointerm));
reportRowCheck.setAllex(Integer.toString(allex));
reportRowCheck.setYesex(Integer.toString(yesex));
reportRowCheck.setSpecex(Integer.toString(specex));
reportRowCheck.setNoex(Integer.toString(noex));
results.add(reportRowCheck);
if (!sessionAlreadyOpened) {
close();
}
return results;
}
public static class ReportRowCheck {
private String id;
private String depparty;
private String allnoVisa;
private String allyesVisa;
private String allinterm;
private String yesinterm;
private String specinterm;
private String nointerm;
private String allex;
private String yesex;
private String specex;
private String noex;
public String getId() {
return id;
}
public String getDepparty() {
return depparty;
}
public String getAllnoVisa() {
return allnoVisa;
}
public String getAllyesVisa() {
return allyesVisa;
}
public String getAllinterm() {
return allinterm;
}
public String getYesinterm() {
return yesinterm;
}
public String getSpecinterm() {
return specinterm;
}
public String getNointerm() {
return nointerm;
}
public String getAllex() {
return allex;
}
public String getYesex() {
return yesex;
}
public String getSpecex() {
return specex;
}
public String getNoex() {
return noex;
}
public void setId(String id) {
this.id = id;
}
public void setDepparty(String depparty) {
this.depparty = depparty;
}
public void setAllnoVisa(String allnoVisa) {
this.allnoVisa = allnoVisa;
}
public void setAllyesVisa(String allyesVisa) {
this.allyesVisa = allyesVisa;
}
public void setAllinterm(String allinterm) {
this.allinterm = allinterm;
}
public void setYesinterm(String yesinterm) {
this.yesinterm = yesinterm;
}
public void setSpecinterm(String specinterm) {
this.specinterm = specinterm;
}
public void setNointerm(String nointerm) {
this.nointerm = nointerm;
}
public void setAllex(String allex) {
this.allex = allex;
}
public void setYesex(String yesex) {
this.yesex = yesex;
}
public void setSpecex(String specex) {
this.specex = specex;
}
public void setNoex(String noex) {
this.noex = noex;
}
}
private ListValue createIdListValue(final List<Id> ids) {
final List<ReferenceValue> values = ids.stream()
.map(ReferenceValue::new)
.collect(Collectors.toList());
return ListValue.createListValue(values);
}
private ListValue createStringListValue(final List<String> values) {
final List<StringValue> refvalues = values.stream()
.map(StringValue::new)
.collect(Collectors.toList());
return ListValue.createListValue(refvalues);
}
private Id idFromKey(String key) {
if (key == null) {
return null;
}
final String[] keyPare = key.split("_");
if (keyPare.length != 2) {
return null;
}
final int typeId = parseInt(keyPare[1]);
final long id = parseLong(keyPare[0]);
return new RdbmsId(typeId, id);
}
public Boolean isBeginStage(String unidAndStage) {
Boolean isBeginStage = true;
AFDate startDate = null;
AFDate currDate = new AFDate(Calendar.getInstance());
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
String startDateStr = getStartDateForStage(unidAndStage);
try {
startDate = AFDate.fromJavaDateSafeTZ(formatter.parse(startDateStr), false);
} catch (ParseException e) {
throw new RuntimeException(e);
}
if (startDate.toJavaDate().after(currDate.toJavaDate())) {
isBeginStage = false;
}
return isBeginStage;
}
public AFDate getDueDateForStage(String unidAndStage) {
AFDate dueTime = null;
String unid = unidAndStage.split("%")[0];
Integer stage = Integer.parseInt(unidAndStage.split("%")[1]);
ARApplicationApproving arApplication = AFSession.get().getApplication(ARApplicationApproving.class);
ARListApproving arList = arApplication.getEntityByUNID(unid);
if (ARStagesApproving.ProcessType.PARALLEL.equals(arList.stages().getProcessType())) {
dueTime = arList.getGlobalDueDate();
} else {
dueTime = arList.stages().get(stage).getFinishTime().toAFDate();
}
return dueTime;
}
public String getStartDateForStage(String unidAndStage) {
String startTimeStr = "";
String unid = unidAndStage.split("%")[0];
Integer stage = Integer.parseInt(unidAndStage.split("%")[1]);
ARApplicationApproving arApplication = AFSession.get().getApplication(ARApplicationApproving.class);
ARListApproving arList = arApplication.getEntityByUNID(unid);
if (ARStagesApproving.ProcessType.PARALLEL.equals(arList.stages().getProcessType())) {
startTimeStr = arList.getStartTime().toAFDate().toString();
} else {
startTimeStr = arList.stages().get(stage).getStartTime().toAFDate().toString();
}
return startTimeStr;
}
}