@Test public void testSaveArrangement() throws Exception { }
public List<ArrangementConflictParam> saveArrangement(Date today, int week, Integer departmentId, Integer arrangementRuleId, List<Arrangement> arrangements, List<ArrangementConflictParam> conflict, Boolean toInsert, List<Arrangement> toInsertArrangements){ HashMap<Integer, Arrangement> arrangementsToday = new HashMap<>(); for(Arrangement arrangement : arrangements){ if(0 == arrangement.getAppointmentDate().compareTo(today)){ arrangementsToday.put(arrangement.getRoleId(), arrangement); } } List<HashMap> arrangementRules = arrangementRuleMapper.getValidById(arrangementRuleId); for(HashMap arrangementRule : arrangementRules) { Byte timeSlot = 0; String weekDate = ""; switch (week) { case 1: weekDate = "mon"; break; case 2: weekDate = "tue"; break; case 3: weekDate = "wed"; break; case 4: weekDate = "thu"; break; case 5: weekDate = "fri"; break; case 6: weekDate = "sat"; break; case 7: weekDate = "sun"; break; } Boolean am = (Boolean) arrangementRule.get(weekDate + "Am"); Boolean pm = (Boolean) arrangementRule.get(weekDate + "Pm"); if(am == true && pm == false){ timeSlot = 1; } else if(am == false && pm == true){ timeSlot = 2; } else if (am == true && pm == true){ timeSlot = 3; } Integer roleId = (Integer)arrangementRule.get("roleId"); Integer userId = roleMapper.getUserIdByRoleId(roleId); for (Map.Entry<Integer, Arrangement> entry : arrangementsToday.entrySet()) { Integer arrangedRoleId = entry.getKey(); Integer theUserId = roleMapper.getUserIdByRoleId(arrangedRoleId); if(userId.equals(theUserId)){ Arrangement arrangement = entry.getValue(); if((timeSlot != 0) && (timeSlot == arrangement.getTimeSlot() || timeSlot == 3 || arrangement.getTimeSlot() == 3)){ ArrangementConflictParam arrangementConflictParam = new ArrangementConflictParam(); arrangementConflictParam.setDate(today); String departmentName = departmentMapper.getNameById(departmentId); arrangementConflictParam.setDepartmentName(departmentName); arrangementConflictParam.setUserName(arrangement.getUserName()); conflict.add(arrangementConflictParam); } } } String roleName = roleMapper.getUserNameByRoleId(roleId); Integer registrationLevelIdInt = (Integer)arrangementRule.get("registrationLevelId"); Integer maxAppointmentInt = (Integer)arrangementRule.get("maxAppointment"); Byte registrationLevelId = registrationLevelIdInt.byteValue(); Byte maxAppointment = maxAppointmentInt.byteValue(); if(timeSlot != 0) { Arrangement arrangement = new Arrangement(); arrangement.setAppointmentDate(today); arrangement.setDepartmentId(departmentId); arrangement.setRoleId(roleId); arrangement.setUserName(roleName); arrangement.setRegistrationLevelId(registrationLevelId); arrangement.setIsValid(true); arrangement.setTimeSlot(timeSlot); arrangement.setMaxAppointment(maxAppointment); arrangement.setAppointmentLeft(maxAppointment); toInsertArrangements.add(arrangement); } } return conflict; }
ArrangementManagementServiceImpl implements ArrangementManagementService { public List<ArrangementConflictParam> saveArrangement(Date today, int week, Integer departmentId, Integer arrangementRuleId, List<Arrangement> arrangements, List<ArrangementConflictParam> conflict, Boolean toInsert, List<Arrangement> toInsertArrangements){ HashMap<Integer, Arrangement> arrangementsToday = new HashMap<>(); for(Arrangement arrangement : arrangements){ if(0 == arrangement.getAppointmentDate().compareTo(today)){ arrangementsToday.put(arrangement.getRoleId(), arrangement); } } List<HashMap> arrangementRules = arrangementRuleMapper.getValidById(arrangementRuleId); for(HashMap arrangementRule : arrangementRules) { Byte timeSlot = 0; String weekDate = ""; switch (week) { case 1: weekDate = "mon"; break; case 2: weekDate = "tue"; break; case 3: weekDate = "wed"; break; case 4: weekDate = "thu"; break; case 5: weekDate = "fri"; break; case 6: weekDate = "sat"; break; case 7: weekDate = "sun"; break; } Boolean am = (Boolean) arrangementRule.get(weekDate + "Am"); Boolean pm = (Boolean) arrangementRule.get(weekDate + "Pm"); if(am == true && pm == false){ timeSlot = 1; } else if(am == false && pm == true){ timeSlot = 2; } else if (am == true && pm == true){ timeSlot = 3; } Integer roleId = (Integer)arrangementRule.get("roleId"); Integer userId = roleMapper.getUserIdByRoleId(roleId); for (Map.Entry<Integer, Arrangement> entry : arrangementsToday.entrySet()) { Integer arrangedRoleId = entry.getKey(); Integer theUserId = roleMapper.getUserIdByRoleId(arrangedRoleId); if(userId.equals(theUserId)){ Arrangement arrangement = entry.getValue(); if((timeSlot != 0) && (timeSlot == arrangement.getTimeSlot() || timeSlot == 3 || arrangement.getTimeSlot() == 3)){ ArrangementConflictParam arrangementConflictParam = new ArrangementConflictParam(); arrangementConflictParam.setDate(today); String departmentName = departmentMapper.getNameById(departmentId); arrangementConflictParam.setDepartmentName(departmentName); arrangementConflictParam.setUserName(arrangement.getUserName()); conflict.add(arrangementConflictParam); } } } String roleName = roleMapper.getUserNameByRoleId(roleId); Integer registrationLevelIdInt = (Integer)arrangementRule.get("registrationLevelId"); Integer maxAppointmentInt = (Integer)arrangementRule.get("maxAppointment"); Byte registrationLevelId = registrationLevelIdInt.byteValue(); Byte maxAppointment = maxAppointmentInt.byteValue(); if(timeSlot != 0) { Arrangement arrangement = new Arrangement(); arrangement.setAppointmentDate(today); arrangement.setDepartmentId(departmentId); arrangement.setRoleId(roleId); arrangement.setUserName(roleName); arrangement.setRegistrationLevelId(registrationLevelId); arrangement.setIsValid(true); arrangement.setTimeSlot(timeSlot); arrangement.setMaxAppointment(maxAppointment); arrangement.setAppointmentLeft(maxAppointment); toInsertArrangements.add(arrangement); } } return conflict; } }
ArrangementManagementServiceImpl implements ArrangementManagementService { public List<ArrangementConflictParam> saveArrangement(Date today, int week, Integer departmentId, Integer arrangementRuleId, List<Arrangement> arrangements, List<ArrangementConflictParam> conflict, Boolean toInsert, List<Arrangement> toInsertArrangements){ HashMap<Integer, Arrangement> arrangementsToday = new HashMap<>(); for(Arrangement arrangement : arrangements){ if(0 == arrangement.getAppointmentDate().compareTo(today)){ arrangementsToday.put(arrangement.getRoleId(), arrangement); } } List<HashMap> arrangementRules = arrangementRuleMapper.getValidById(arrangementRuleId); for(HashMap arrangementRule : arrangementRules) { Byte timeSlot = 0; String weekDate = ""; switch (week) { case 1: weekDate = "mon"; break; case 2: weekDate = "tue"; break; case 3: weekDate = "wed"; break; case 4: weekDate = "thu"; break; case 5: weekDate = "fri"; break; case 6: weekDate = "sat"; break; case 7: weekDate = "sun"; break; } Boolean am = (Boolean) arrangementRule.get(weekDate + "Am"); Boolean pm = (Boolean) arrangementRule.get(weekDate + "Pm"); if(am == true && pm == false){ timeSlot = 1; } else if(am == false && pm == true){ timeSlot = 2; } else if (am == true && pm == true){ timeSlot = 3; } Integer roleId = (Integer)arrangementRule.get("roleId"); Integer userId = roleMapper.getUserIdByRoleId(roleId); for (Map.Entry<Integer, Arrangement> entry : arrangementsToday.entrySet()) { Integer arrangedRoleId = entry.getKey(); Integer theUserId = roleMapper.getUserIdByRoleId(arrangedRoleId); if(userId.equals(theUserId)){ Arrangement arrangement = entry.getValue(); if((timeSlot != 0) && (timeSlot == arrangement.getTimeSlot() || timeSlot == 3 || arrangement.getTimeSlot() == 3)){ ArrangementConflictParam arrangementConflictParam = new ArrangementConflictParam(); arrangementConflictParam.setDate(today); String departmentName = departmentMapper.getNameById(departmentId); arrangementConflictParam.setDepartmentName(departmentName); arrangementConflictParam.setUserName(arrangement.getUserName()); conflict.add(arrangementConflictParam); } } } String roleName = roleMapper.getUserNameByRoleId(roleId); Integer registrationLevelIdInt = (Integer)arrangementRule.get("registrationLevelId"); Integer maxAppointmentInt = (Integer)arrangementRule.get("maxAppointment"); Byte registrationLevelId = registrationLevelIdInt.byteValue(); Byte maxAppointment = maxAppointmentInt.byteValue(); if(timeSlot != 0) { Arrangement arrangement = new Arrangement(); arrangement.setAppointmentDate(today); arrangement.setDepartmentId(departmentId); arrangement.setRoleId(roleId); arrangement.setUserName(roleName); arrangement.setRegistrationLevelId(registrationLevelId); arrangement.setIsValid(true); arrangement.setTimeSlot(timeSlot); arrangement.setMaxAppointment(maxAppointment); arrangement.setAppointmentLeft(maxAppointment); toInsertArrangements.add(arrangement); } } return conflict; }  }
ArrangementManagementServiceImpl implements ArrangementManagementService { public List<ArrangementConflictParam> saveArrangement(Date today, int week, Integer departmentId, Integer arrangementRuleId, List<Arrangement> arrangements, List<ArrangementConflictParam> conflict, Boolean toInsert, List<Arrangement> toInsertArrangements){ HashMap<Integer, Arrangement> arrangementsToday = new HashMap<>(); for(Arrangement arrangement : arrangements){ if(0 == arrangement.getAppointmentDate().compareTo(today)){ arrangementsToday.put(arrangement.getRoleId(), arrangement); } } List<HashMap> arrangementRules = arrangementRuleMapper.getValidById(arrangementRuleId); for(HashMap arrangementRule : arrangementRules) { Byte timeSlot = 0; String weekDate = ""; switch (week) { case 1: weekDate = "mon"; break; case 2: weekDate = "tue"; break; case 3: weekDate = "wed"; break; case 4: weekDate = "thu"; break; case 5: weekDate = "fri"; break; case 6: weekDate = "sat"; break; case 7: weekDate = "sun"; break; } Boolean am = (Boolean) arrangementRule.get(weekDate + "Am"); Boolean pm = (Boolean) arrangementRule.get(weekDate + "Pm"); if(am == true && pm == false){ timeSlot = 1; } else if(am == false && pm == true){ timeSlot = 2; } else if (am == true && pm == true){ timeSlot = 3; } Integer roleId = (Integer)arrangementRule.get("roleId"); Integer userId = roleMapper.getUserIdByRoleId(roleId); for (Map.Entry<Integer, Arrangement> entry : arrangementsToday.entrySet()) { Integer arrangedRoleId = entry.getKey(); Integer theUserId = roleMapper.getUserIdByRoleId(arrangedRoleId); if(userId.equals(theUserId)){ Arrangement arrangement = entry.getValue(); if((timeSlot != 0) && (timeSlot == arrangement.getTimeSlot() || timeSlot == 3 || arrangement.getTimeSlot() == 3)){ ArrangementConflictParam arrangementConflictParam = new ArrangementConflictParam(); arrangementConflictParam.setDate(today); String departmentName = departmentMapper.getNameById(departmentId); arrangementConflictParam.setDepartmentName(departmentName); arrangementConflictParam.setUserName(arrangement.getUserName()); conflict.add(arrangementConflictParam); } } } String roleName = roleMapper.getUserNameByRoleId(roleId); Integer registrationLevelIdInt = (Integer)arrangementRule.get("registrationLevelId"); Integer maxAppointmentInt = (Integer)arrangementRule.get("maxAppointment"); Byte registrationLevelId = registrationLevelIdInt.byteValue(); Byte maxAppointment = maxAppointmentInt.byteValue(); if(timeSlot != 0) { Arrangement arrangement = new Arrangement(); arrangement.setAppointmentDate(today); arrangement.setDepartmentId(departmentId); arrangement.setRoleId(roleId); arrangement.setUserName(roleName); arrangement.setRegistrationLevelId(registrationLevelId); arrangement.setIsValid(true); arrangement.setTimeSlot(timeSlot); arrangement.setMaxAppointment(maxAppointment); arrangement.setAppointmentLeft(maxAppointment); toInsertArrangements.add(arrangement); } } return conflict; }  @Override CommonResult insertArrangementRule(ArrangementRuleParam arrangementRuleParam); @Override CommonResult listArrangementRules(Integer departmentId); @Override CommonResult insertArrangement(ArrangementParam arrangementParam); List<ArrangementConflictParam> saveArrangement(Date today, int week, Integer departmentId,
                                                          Integer arrangementRuleId, List<Arrangement> arrangements,
                                                          List<ArrangementConflictParam> conflict, Boolean toInsert,
                                                          List<Arrangement> toInsertArrangements); @Override CommonResult listArrangements(Date startDate, Date endDate, Integer departmentId); String getStatusStr(Boolean isValid); @Override CommonResult modifyArrangements(ArrangementParam arrangementParam); @Override CommonResult modifyArrangement(Integer arrangementId, Byte timeSlot); JSONObject formatJson(JSONObject jsonObject, List<HashMap> arrangementRule); }
ArrangementManagementServiceImpl implements ArrangementManagementService { public List<ArrangementConflictParam> saveArrangement(Date today, int week, Integer departmentId, Integer arrangementRuleId, List<Arrangement> arrangements, List<ArrangementConflictParam> conflict, Boolean toInsert, List<Arrangement> toInsertArrangements){ HashMap<Integer, Arrangement> arrangementsToday = new HashMap<>(); for(Arrangement arrangement : arrangements){ if(0 == arrangement.getAppointmentDate().compareTo(today)){ arrangementsToday.put(arrangement.getRoleId(), arrangement); } } List<HashMap> arrangementRules = arrangementRuleMapper.getValidById(arrangementRuleId); for(HashMap arrangementRule : arrangementRules) { Byte timeSlot = 0; String weekDate = ""; switch (week) { case 1: weekDate = "mon"; break; case 2: weekDate = "tue"; break; case 3: weekDate = "wed"; break; case 4: weekDate = "thu"; break; case 5: weekDate = "fri"; break; case 6: weekDate = "sat"; break; case 7: weekDate = "sun"; break; } Boolean am = (Boolean) arrangementRule.get(weekDate + "Am"); Boolean pm = (Boolean) arrangementRule.get(weekDate + "Pm"); if(am == true && pm == false){ timeSlot = 1; } else if(am == false && pm == true){ timeSlot = 2; } else if (am == true && pm == true){ timeSlot = 3; } Integer roleId = (Integer)arrangementRule.get("roleId"); Integer userId = roleMapper.getUserIdByRoleId(roleId); for (Map.Entry<Integer, Arrangement> entry : arrangementsToday.entrySet()) { Integer arrangedRoleId = entry.getKey(); Integer theUserId = roleMapper.getUserIdByRoleId(arrangedRoleId); if(userId.equals(theUserId)){ Arrangement arrangement = entry.getValue(); if((timeSlot != 0) && (timeSlot == arrangement.getTimeSlot() || timeSlot == 3 || arrangement.getTimeSlot() == 3)){ ArrangementConflictParam arrangementConflictParam = new ArrangementConflictParam(); arrangementConflictParam.setDate(today); String departmentName = departmentMapper.getNameById(departmentId); arrangementConflictParam.setDepartmentName(departmentName); arrangementConflictParam.setUserName(arrangement.getUserName()); conflict.add(arrangementConflictParam); } } } String roleName = roleMapper.getUserNameByRoleId(roleId); Integer registrationLevelIdInt = (Integer)arrangementRule.get("registrationLevelId"); Integer maxAppointmentInt = (Integer)arrangementRule.get("maxAppointment"); Byte registrationLevelId = registrationLevelIdInt.byteValue(); Byte maxAppointment = maxAppointmentInt.byteValue(); if(timeSlot != 0) { Arrangement arrangement = new Arrangement(); arrangement.setAppointmentDate(today); arrangement.setDepartmentId(departmentId); arrangement.setRoleId(roleId); arrangement.setUserName(roleName); arrangement.setRegistrationLevelId(registrationLevelId); arrangement.setIsValid(true); arrangement.setTimeSlot(timeSlot); arrangement.setMaxAppointment(maxAppointment); arrangement.setAppointmentLeft(maxAppointment); toInsertArrangements.add(arrangement); } } return conflict; }  @Override CommonResult insertArrangementRule(ArrangementRuleParam arrangementRuleParam); @Override CommonResult listArrangementRules(Integer departmentId); @Override CommonResult insertArrangement(ArrangementParam arrangementParam); List<ArrangementConflictParam> saveArrangement(Date today, int week, Integer departmentId,
                                                          Integer arrangementRuleId, List<Arrangement> arrangements,
                                                          List<ArrangementConflictParam> conflict, Boolean toInsert,
                                                          List<Arrangement> toInsertArrangements); @Override CommonResult listArrangements(Date startDate, Date endDate, Integer departmentId); String getStatusStr(Boolean isValid); @Override CommonResult modifyArrangements(ArrangementParam arrangementParam); @Override CommonResult modifyArrangement(Integer arrangementId, Byte timeSlot); JSONObject formatJson(JSONObject jsonObject, List<HashMap> arrangementRule);  }