公共无效更新(AdmWeightageDefinitionDBO t) { sessionFactory.withTransaction((session, tx) -> session.merge(t)).subscribeAsCompletionStage(); }
问问题
48 次
1 回答
0
//fetch parent and childs
public Mono < AdmWeightageDefinitionDBO > edit(int id) {
String str = "select bo from AdmWeightageDefinitionDBO bo " +
" left join fetch bo.admWeightageDefinitionDetailDBOsSet " +
" left join fetch bo.admWeightageDefinitionGeneralDBOsSet " +
" left join fetch bo.admWeightageDefinitionLocationCampusDBOsSet " +
" where bo.recordStatus = 'A' and bo.id=:id ";
return Mono.fromFuture(sessionFactory.withSession(session - > session.createQuery(str, AdmWeightageDefinitionDBO.class)
.setParameter("id", id).getSingleResult()).subscribeAsCompletionStage());
}
public Mono < ApiResult > saveOrUpdate(Mono < AdmWeightageDefinitionDTO > dto, String userId) {
Mono < AdmWeightageDefinitionDTO > mono = dto
.handle((admWeightageDefinitionDTO, synchronousSink) - > {
boolean istrue = weightageDefinitionSettingsTransaction.duplicateCheck(admWeightageDefinitionDTO);
if (istrue) {
synchronousSink.error(new DuplicateException("duplicate"));
} else {
synchronousSink.next(admWeightageDefinitionDTO);
}
}).cast(AdmWeightageDefinitionDTO.class);
return mono.map(data - > convertFunc.apply(data, userId))
.flatMap(t - > {
return t.flatMap(item - > {
//save parent and child try to merge
weightageDefinitionSettingsTransaction.update(item);
return Mono.just(Boolean.TRUE);
});
}).map(Utils::responseResult);
}
public BiFunction < AdmWeightageDefinitionDTO, String, Mono < AdmWeightageDefinitionDBO >> convertFunc = (dto, userId) - > {
if (!Utils.isNullOrEmpty(dto.getId())) {
// get parent and child and modifing new childs adding and updating existing
return weightageDefinitionSettingsTransaction.edit(dto.getId()).map(dbo - > {
if (!Utils.isNullOrEmpty(dto.getOverallTotal())) {
dbo.setOverallTotal(dto.getOverallTotal());
}
if (!Utils.isNullOrEmpty(dto.getPreRequisiteWeigtageTotal())) {
dbo.setPreRequisiteWeigtageTotal(dto.getPreRequisiteWeigtageTotal());
}
if (!Utils.isNullOrEmpty(dto.getEducationWeightageTotal())) {
dbo.setEducationWeightageTotal(dto.getEducationWeightageTotal());
}
if (!Utils.isNullOrEmpty(dto.getErpAcademicYearDTO()) && !Utils.isNullOrEmpty(dto.getErpAcademicYearDTO().getValue())) {
ErpAcademicYearDBO erpAcademicYearDbo = new ErpAcademicYearDBO();
erpAcademicYearDbo.setId(Integer.parseInt(dto.getErpAcademicYearDTO().getValue()));
dbo.setErpAcademicYearDBO(erpAcademicYearDbo);
}
if (!Utils.isNullOrEmpty(dto.getErpProgrammeDTO()) && !Utils.isNullOrEmpty(dto.getErpProgrammeDTO().getValue())) {
ErpProgrammeDBO erpProgrammeDBO = new ErpProgrammeDBO();
erpProgrammeDBO.setId(Integer.parseInt(dto.getErpProgrammeDTO().getValue()));
dbo.setErpProgrammeDBO(erpProgrammeDBO);
}
if (!Utils.isNullOrEmpty(dto.getId()))
dbo.setModifiedUsersId(Integer.parseInt(userId));
else
dbo.setCreatedUsersId(Integer.parseInt(userId));
dbo.setRecordStatus('A');
Set < AdmWeightageDefinitionDetailDBO > weightageDefinitionDetailDBOsSet = dbo.getAdmWeightageDefinitionDetailDBOsSet();
Set < AdmWeightageDefinitionGeneralDBO > set = dbo.getAdmWeightageDefinitionGeneralDBOsSet();
Set < AdmWeightageDefinitionGeneralDBO > setNew = new HashSet < AdmWeightageDefinitionGeneralDBO > ();
set.forEach(item - > {
dto.getAdmWeightageDefinitionGeneralDTOsSet().forEach(itemP - > {
itemP.getErpReservationCategoryDTOList().forEach(itemR - > {
if (!Utils.isNullOrEmpty(item.getId()) && !Utils.isNullOrEmpty(itemR.getParentId()) && item.getId().equals(itemR.getParentId())) {
AdmWeightageDefinitionGeneralDBO generalDBO = new AdmWeightageDefinitionGeneralDBO();
generalDBO.setAdmWeightageDefinitionDBO(dbo);
generalDBO.setErpReservationCategoryDBO(new ErpReservationCategoryDBO());
ErpReservationCategoryDBO erpReservationCategoryDBO = new ErpReservationCategoryDBO();
erpReservationCategoryDBO.setId(3);
generalDBO.setErpReservationCategoryDBO(erpReservationCategoryDBO);
generalDBO.setScore(40);
setNew.add(generalDBO);
}
});
});
});
dbo.setAdmWeightageDefinitionGeneralDBOsSet(setNew);
// return ConvertDtoToDBO(dbo1, dto, userId);
return dbo;
});
} else {
return Mono.just(ConvertDtoToDBO(new AdmWeightageDefinitionDBO(), dto, userId));
}
};
//merge parent and childern
public void update(AdmWeightageDefinitionDBO t) {
sessionFactory.withTransaction((session, tx) - > session.merge(t)).subscribeAsCompletionStage();
}
// not merging new child and existing child different object not updating
于 2021-08-25T10:15:43.663 回答