private EmployeePlan createEmployeePlanIfNeed( Integer year, Integer month, Employee employee, DictionaryItem dictionaryItem) { EmployeePlan employeePlan = employeePlanService.tryFind(employee, year, month, dictionaryItem); if (employeePlan == null) { employeePlan = new EmployeePlan(); employeePlan.setType(dictionaryItem); employeePlan.setEmployee(employee); employeePlan.setYear(year); employeePlan.setMonth(month); } return employeePlan; }
@Transactional(propagation = Propagation.REQUIRES_NEW) public void savePlans(JsonRootNode rootNode, Integer year, Integer month) { final Calendar calendar = DateTimeUtil.getCalendar(year, month); if (DateUtils.truncatedCompareTo(new Date(), calendar.getTime(), Calendar.MONTH) > 0) { throw new IllegalArgumentException("Редактирование планов за предыдущий месяц запрещено"); } final List<EmployeePlan> employeePlans = new ArrayList<EmployeePlan>(); final List<EmployeeProjectPlan> employeeProjectPlans = new ArrayList<EmployeeProjectPlan>(); processJsonDataItems(employeePlans, employeeProjectPlans, rootNode, year, month); employeePlanService.mergeProjectPlans(employeePlans); employeeProjectPlanService.mergeEmployeeProjectPlans(employeeProjectPlans); }