@Override
protected void onSaveOrModify(EmployeeSalaryDO obj)
{
if (obj.getId() == null) {
List<EmployeeSalaryDO> list = pfEmgrFactory.runRoTrans(emgr -> {
return emgr.select(EmployeeSalaryDO.class, "SELECT s FROM EmployeeSalaryDO s WHERE s.year = :year and s.month = :month and s.employee.id = :employeeid",
"year", obj.getYear(), "month", obj.getMonth(), "employeeid", obj.getEmployeeId());
});
if (CollectionUtils.isNotEmpty(list)) {
log.info("Insert of EmployeeSalaryDO not possible. There is a existing one for employee with id: " + obj.getEmployeeId() + " and year: " +
obj.getYear() + " and month: " + obj.getMonth() + " . Existing one: " + list.get(0).toString());
throw new UserException("fibu.employee.salary.error.salaryAlreadyExist");
}
} else {
List<EmployeeSalaryDO> list = pfEmgrFactory.runRoTrans(emgr -> {
return emgr
.select(EmployeeSalaryDO.class,
"SELECT s FROM EmployeeSalaryDO s WHERE s.year = :year and s.month = :month and s.employee.id = :employeeid and s.id <> :id",
"year", obj.getYear(), "month", obj.getMonth(), "employeeid", obj.getEmployeeId(), "id", obj.getId());
});
if (CollectionUtils.isNotEmpty(list)) {
log.info("Update of EmployeeSalaryDO not possible. There is a existing one for employee with id: " + obj.getEmployeeId() + " and year: " +
obj.getYear() + " and month: " + obj.getMonth() + " and ID: " + obj.getId() + " . Existing one: " + list.get(0).toString());
throw new UserException("fibu.employee.salary.error.salaryAlreadyExist");
}
}
}