@Test public void testInsertArrangement() throws Exception { }
@Override public CommonResult insertArrangement(ArrangementParam arrangementParam){ Boolean toInsert = true; toInsertArrangements = new ArrayList<>(); Date startDate = Date.valueOf(arrangementParam.getStartDate()); Date endDate = Date.valueOf(arrangementParam.getEndDate()); Integer departmentId = arrangementParam.getDepartmentId(); Integer arrangementRuleId = arrangementParam.getId(); if(startDate.compareTo(endDate) > 0) return CommonResult.fail(ResultCode.E_809); if(arrangementRuleId == null) return CommonResult.fail(ResultCode.E_801); if(0!= arrangementMapper.listByDepartmentIdAndDatePeriod(startDate, endDate, departmentId).size()){ return CommonResult.fail(ResultCode.E_810); } List<Arrangement> arrangements = arrangementMapper.listByUserIdAndDatePeriod(startDate, endDate); Date today = startDate; List<ArrangementConflictParam> conflict = new ArrayList<>(); while(today.compareTo(endDate) <= 0){ Calendar calendar = Calendar.getInstance(); calendar.setTime(today); int week = calendar.get(Calendar.DAY_OF_WEEK); conflict = saveArrangement(today, week, departmentId, arrangementRuleId, arrangements, conflict, toInsert, toInsertArrangements); if(0 != conflict.size()) toInsert = false; calendar.add(Calendar.DAY_OF_MONTH, 1); java.util.Date tomorrow = calendar.getTime(); today = new Date(tomorrow.getTime()); } if(toInsert.equals(true)){ for(Arrangement arrangement : toInsertArrangements) arrangementMapper.insertSelective(arrangement); } if(0 != conflict.size()) return CommonResult.fail(ResultCode.E_808, conflict); else return CommonResult.success("OK"); }
ArrangementManagementServiceImpl implements ArrangementManagementService { @Override public CommonResult insertArrangement(ArrangementParam arrangementParam){ Boolean toInsert = true; toInsertArrangements = new ArrayList<>(); Date startDate = Date.valueOf(arrangementParam.getStartDate()); Date endDate = Date.valueOf(arrangementParam.getEndDate()); Integer departmentId = arrangementParam.getDepartmentId(); Integer arrangementRuleId = arrangementParam.getId(); if(startDate.compareTo(endDate) > 0) return CommonResult.fail(ResultCode.E_809); if(arrangementRuleId == null) return CommonResult.fail(ResultCode.E_801); if(0!= arrangementMapper.listByDepartmentIdAndDatePeriod(startDate, endDate, departmentId).size()){ return CommonResult.fail(ResultCode.E_810); } List<Arrangement> arrangements = arrangementMapper.listByUserIdAndDatePeriod(startDate, endDate); Date today = startDate; List<ArrangementConflictParam> conflict = new ArrayList<>(); while(today.compareTo(endDate) <= 0){ Calendar calendar = Calendar.getInstance(); calendar.setTime(today); int week = calendar.get(Calendar.DAY_OF_WEEK); conflict = saveArrangement(today, week, departmentId, arrangementRuleId, arrangements, conflict, toInsert, toInsertArrangements); if(0 != conflict.size()) toInsert = false; calendar.add(Calendar.DAY_OF_MONTH, 1); java.util.Date tomorrow = calendar.getTime(); today = new Date(tomorrow.getTime()); } if(toInsert.equals(true)){ for(Arrangement arrangement : toInsertArrangements) arrangementMapper.insertSelective(arrangement); } if(0 != conflict.size()) return CommonResult.fail(ResultCode.E_808, conflict); else return CommonResult.success("OK"); } }
ArrangementManagementServiceImpl implements ArrangementManagementService { @Override public CommonResult insertArrangement(ArrangementParam arrangementParam){ Boolean toInsert = true; toInsertArrangements = new ArrayList<>(); Date startDate = Date.valueOf(arrangementParam.getStartDate()); Date endDate = Date.valueOf(arrangementParam.getEndDate()); Integer departmentId = arrangementParam.getDepartmentId(); Integer arrangementRuleId = arrangementParam.getId(); if(startDate.compareTo(endDate) > 0) return CommonResult.fail(ResultCode.E_809); if(arrangementRuleId == null) return CommonResult.fail(ResultCode.E_801); if(0!= arrangementMapper.listByDepartmentIdAndDatePeriod(startDate, endDate, departmentId).size()){ return CommonResult.fail(ResultCode.E_810); } List<Arrangement> arrangements = arrangementMapper.listByUserIdAndDatePeriod(startDate, endDate); Date today = startDate; List<ArrangementConflictParam> conflict = new ArrayList<>(); while(today.compareTo(endDate) <= 0){ Calendar calendar = Calendar.getInstance(); calendar.setTime(today); int week = calendar.get(Calendar.DAY_OF_WEEK); conflict = saveArrangement(today, week, departmentId, arrangementRuleId, arrangements, conflict, toInsert, toInsertArrangements); if(0 != conflict.size()) toInsert = false; calendar.add(Calendar.DAY_OF_MONTH, 1); java.util.Date tomorrow = calendar.getTime(); today = new Date(tomorrow.getTime()); } if(toInsert.equals(true)){ for(Arrangement arrangement : toInsertArrangements) arrangementMapper.insertSelective(arrangement); } if(0 != conflict.size()) return CommonResult.fail(ResultCode.E_808, conflict); else return CommonResult.success("OK"); }  }
ArrangementManagementServiceImpl implements ArrangementManagementService { @Override public CommonResult insertArrangement(ArrangementParam arrangementParam){ Boolean toInsert = true; toInsertArrangements = new ArrayList<>(); Date startDate = Date.valueOf(arrangementParam.getStartDate()); Date endDate = Date.valueOf(arrangementParam.getEndDate()); Integer departmentId = arrangementParam.getDepartmentId(); Integer arrangementRuleId = arrangementParam.getId(); if(startDate.compareTo(endDate) > 0) return CommonResult.fail(ResultCode.E_809); if(arrangementRuleId == null) return CommonResult.fail(ResultCode.E_801); if(0!= arrangementMapper.listByDepartmentIdAndDatePeriod(startDate, endDate, departmentId).size()){ return CommonResult.fail(ResultCode.E_810); } List<Arrangement> arrangements = arrangementMapper.listByUserIdAndDatePeriod(startDate, endDate); Date today = startDate; List<ArrangementConflictParam> conflict = new ArrayList<>(); while(today.compareTo(endDate) <= 0){ Calendar calendar = Calendar.getInstance(); calendar.setTime(today); int week = calendar.get(Calendar.DAY_OF_WEEK); conflict = saveArrangement(today, week, departmentId, arrangementRuleId, arrangements, conflict, toInsert, toInsertArrangements); if(0 != conflict.size()) toInsert = false; calendar.add(Calendar.DAY_OF_MONTH, 1); java.util.Date tomorrow = calendar.getTime(); today = new Date(tomorrow.getTime()); } if(toInsert.equals(true)){ for(Arrangement arrangement : toInsertArrangements) arrangementMapper.insertSelective(arrangement); } if(0 != conflict.size()) return CommonResult.fail(ResultCode.E_808, conflict); else return CommonResult.success("OK"); }  @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 { @Override public CommonResult insertArrangement(ArrangementParam arrangementParam){ Boolean toInsert = true; toInsertArrangements = new ArrayList<>(); Date startDate = Date.valueOf(arrangementParam.getStartDate()); Date endDate = Date.valueOf(arrangementParam.getEndDate()); Integer departmentId = arrangementParam.getDepartmentId(); Integer arrangementRuleId = arrangementParam.getId(); if(startDate.compareTo(endDate) > 0) return CommonResult.fail(ResultCode.E_809); if(arrangementRuleId == null) return CommonResult.fail(ResultCode.E_801); if(0!= arrangementMapper.listByDepartmentIdAndDatePeriod(startDate, endDate, departmentId).size()){ return CommonResult.fail(ResultCode.E_810); } List<Arrangement> arrangements = arrangementMapper.listByUserIdAndDatePeriod(startDate, endDate); Date today = startDate; List<ArrangementConflictParam> conflict = new ArrayList<>(); while(today.compareTo(endDate) <= 0){ Calendar calendar = Calendar.getInstance(); calendar.setTime(today); int week = calendar.get(Calendar.DAY_OF_WEEK); conflict = saveArrangement(today, week, departmentId, arrangementRuleId, arrangements, conflict, toInsert, toInsertArrangements); if(0 != conflict.size()) toInsert = false; calendar.add(Calendar.DAY_OF_MONTH, 1); java.util.Date tomorrow = calendar.getTime(); today = new Date(tomorrow.getTime()); } if(toInsert.equals(true)){ for(Arrangement arrangement : toInsertArrangements) arrangementMapper.insertSelective(arrangement); } if(0 != conflict.size()) return CommonResult.fail(ResultCode.E_808, conflict); else return CommonResult.success("OK"); }  @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);  }