List of usage examples for org.joda.time.format DateTimeFormatter parseLocalDate
public LocalDate parseLocalDate(String text)
From source file:ru.codemine.ccms.router.TaskRouter.java
License:Open Source License
@Secured("ROLE_OFFICE") @RequestMapping(value = "/reports/tasks", method = RequestMethod.GET) public String tasksReport(ModelMap model, @RequestParam(required = false) String dateStartStr, @RequestParam(required = false) String dateEndStr) { model.addAllAttributes(utils.prepareModel()); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY"); LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1) : formatter.parseLocalDate(dateStartStr); LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue() : formatter.parseLocalDate(dateEndStr); if (dateEnd.isBefore(dateStart)) dateEnd = dateStart;// w w w.j av a 2s .c o m model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY")); model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY")); return "reports/tasks-byuser"; }
From source file:ru.codemine.ccms.router.TaskRouter.java
License:Open Source License
@Secured("ROLE_OFFICE") @RequestMapping(value = "/reports/tasks/data", method = RequestMethod.GET) public @ResponseBody List<Map<String, Object>> tasksReportData(ModelMap model, @RequestParam(required = false) String dateStartStr, @RequestParam(required = false) String dateEndStr) { List<Map<String, Object>> recordsList = new ArrayList<>(); List<Employee> allEmps = employeeService.getActive(); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY"); LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1) : formatter.parseLocalDate(dateStartStr); LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue() : formatter.parseLocalDate(dateEndStr); for (Employee employee : allEmps) { Map<String, Object> record = new HashMap<>(); Integer tasksClosed = taskService.getClosedTasksByPerformerCount(employee, dateStart, dateEnd); Integer tasksOverdue = taskService.getOverdueTasksByPerformerCount(employee, dateStart, dateEnd); record.put("username", employee.getFullName()); record.put("tasksClosed", tasksClosed); record.put("tasksOverdue", tasksOverdue); record.put("overduePercent", tasksClosed == 0 ? 0.0 : tasksOverdue.doubleValue() / tasksClosed * 100); record.put("midTime", taskService.getMidTimeByPerformerStr(employee, dateStart, dateEnd)); recordsList.add(record);//from www . j av a 2 s. c o m } return recordsList; }
From source file:ru.codemine.ccms.router.TaskRouter.java
License:Open Source License
@Secured("ROLE_OFFICE") @RequestMapping(value = "/reports/tasks/details", method = RequestMethod.GET) public @ResponseBody List<Map<String, Object>> tasksReportDetails(ModelMap model, @RequestParam String dateStartStr, @RequestParam String dateEndStr, @RequestParam String userFullName) { List<Map<String, Object>> recordsList = new ArrayList<>(); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY"); LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1) : formatter.parseLocalDate(dateStartStr); LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue() : formatter.parseLocalDate(dateEndStr); List<Employee> employees = employeeService.getByFullName(userFullName); if (employees.size() != 1) return recordsList; Employee employee = employees.get(0); for (Task task : taskService.getByPerformerAndCloseTimeInPeriod(employee, dateStart, dateEnd)) { Map<String, Object> record = new HashMap<>(); record.put("taskName", task.getTitle()); record.put("closeTime", task.getCloseTime().toString("dd.MM.YY HH:mm")); record.put("progressTime", task.getProgressTimeStr()); recordsList.add(record);/* w ww . j ava2 s. com*/ } return recordsList; }
From source file:ru.codemine.ccms.sales.domino.DominoSalesLoader.java
License:Open Source License
private Map<LocalDate, Map<String, Sales>> getSalesMap() { File path = new File(settingsService.getStorageEmailPath()); FilenameFilter filter = new EndsWithFilenameFilter(".xls", EndsWithFilenameFilter.NEVER); Map<LocalDate, Map<String, Sales>> result = new HashMap(); for (File file : path.listFiles(filter)) { try {/* w w w .j ava2 s . c o m*/ log.info(" : " + file.getName()); FileInputStream fs = new FileInputStream(file); HSSFWorkbook workbook = new HSSFWorkbook(fs); HSSFSheet sheet = workbook.getSheetAt(0); boolean dateFound = false; boolean colFound = false; Integer colNumber = 0; LocalDate fileDate = null; Map<String, Sales> parsedFileMap = new HashMap(); for (Row row : sheet) { Cell firstCell = row.getCell(0); // // ? // if (firstCell.getCellType() == Cell.CELL_TYPE_STRING && firstCell.getStringCellValue() .startsWith(" ")) { String bothDatesStr = firstCell.getStringCellValue() .replace(" ? ", ""); String[] datesStr = bothDatesStr.split(" "); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY"); LocalDate startDate = formatter.parseLocalDate(datesStr[0]); LocalDate endDate = formatter.parseLocalDate(datesStr[1]); if (startDate != null && startDate.isEqual(endDate)) { dateFound = true; fileDate = startDate; log.info(" : " + fileDate); } } // // ? ? ? ? ? // else if (firstCell.getCellType() == Cell.CELL_TYPE_STRING && firstCell.getStringCellValue().startsWith(" /")) { for (Cell headersCell : row) { if (headersCell.getCellType() == Cell.CELL_TYPE_STRING && headersCell .getStringCellValue().startsWith(" ??")) { colFound = true; colNumber = headersCell.getColumnIndex(); log.info(" : " + colNumber); } } } // // ? ? // else if (dateFound && colFound && firstCell.getCellType() == Cell.CELL_TYPE_STRING && firstCell.getStringCellValue().startsWith(":")) { Sales sale = new Sales(); // ? String namesStr = firstCell.getStringCellValue().replace(": ", ""); String delimiter = " - "; if (namesStr.indexOf(delimiter) > 0 && namesStr.indexOf(delimiter) != namesStr.lastIndexOf(delimiter)) { String name = namesStr.substring(namesStr.indexOf(delimiter) + delimiter.length(), namesStr.lastIndexOf(delimiter)); // ? boolean shopFinished = false; int rcrd = 1; int cashb_rcrd = 0; while (!shopFinished) { Row r = sheet.getRow(row.getRowNum() + rcrd); if (r.getCell(0).getCellType() == Cell.CELL_TYPE_NUMERIC) // ? ? { Double val = r.getCell(colNumber).getNumericCellValue(); //log.debug("i is: " + i + ", val is: " + val); if (val > 0) sale.setValue(sale.getValue() + val); // else { sale.setCashback(sale.getCashback() - val); // cashb_rcrd++; } } else if (r.getCell(0).getStringCellValue().startsWith(" :")) { //log.debug("finished shop record, i is: " + i); sale.setChequeCount(rcrd - cashb_rcrd - 1); shopFinished = true; } rcrd++; } parsedFileMap.put(name, sale); //Double value = row.getCell(colNumber).getNumericCellValue(); //parsedFileMap.put(name, value); //log.debug("Recieved file map: " + parsedFileMap); } } } // foreach row in sheet if (dateFound && colFound) { result.put(fileDate, parsedFileMap); log.info("...ok"); Files.delete(file.toPath()); } else { if (!dateFound) { log.warn(" " + file.getName()); } if (!colFound) { log.warn(" ? " + file.getName()); } log.error("? " + file.getName()); } } catch (Exception e) { //e.printStackTrace(); log.error("? , : " + e.getMessage()); } } // foreach file in path return result; }
From source file:ru.codemine.ccms.utils.Utils.java
License:Open Source License
/** * - // w ww .jav a 2s. c o m * @param dateMonth * ?? * @param dateYear * * @return */ public Map<Shop, SalesMeta> getShopSalesMap(String dateMonth, String dateYear) { LocalDate selectedStartDate; LocalDate selectedEndDate; DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMMM YYYY"); if (dateMonth != null && dateYear != null) // { selectedStartDate = formatter.parseLocalDate("01 " + dateMonth + " " + dateYear); selectedEndDate = selectedStartDate.dayOfMonth().withMaximumValue(); } else // - ??, { selectedStartDate = LocalDate.now().withDayOfMonth(1); selectedEndDate = selectedStartDate.dayOfMonth().withMaximumValue(); } List<Shop> shopList = shopService.getAllOpen(); Map<Shop, SalesMeta> salesMap = new LinkedHashMap(); for (Shop shop : shopList) { SalesMeta sm = salesService.getByShopAndDate(shop, selectedStartDate, selectedEndDate); if (shop.isCountersEnabled()) { for (Sales sales : sm.getSales()) { Counter counter = counterService.getByShopAndDate(shop, sales.getDate().toDateTime(LocalTime.MIDNIGHT)); sales.setPassability(counter == null ? 0 : counter.getIn()); } } salesMap.put(shop, sm); } return salesMap; }
From source file:vn.webapp.controller.cp.ExamController.java
@RequestMapping(value = "saveExamFromSIS", method = RequestMethod.POST) public String saveExamFromSIS(HttpServletRequest request, @Valid @ModelAttribute("examAdd") ExamValidationFromSIS examValidation, BindingResult result, Map model, HttpSession session) {//from w ww .ja v a2s .c o m /* * Get list of paper category and journalList */ /* * Put data back to view */ if (result.hasErrors()) { return "cp.addExam"; } else { String StatusMessages = ""; try { List<ExamStatus> EXS_List = examStatusService.loadEXSList(); boolean isToAdd = true; for (ExamStatus EXS : EXS_List) { if ((EXS.getEXS_AcaYear_Code().equals(examValidation.getAcademicYear())) && (EXS.getEXS_Semester() == examValidation.getSemester())) { isToAdd = false; break; } } if (isToAdd) examStatusService.save(examValidation.getAcademicYear(), examValidation.getSemester(), 1); ReadExamInfos examData = new ReadExamInfos(); List<ExamInfo> examinfos = new ArrayList<ExamInfo>(); String classCode = ""; String courseCode = ""; String courseName = ""; String week = ""; String day = ""; String date = ""; String turn = ""; String slots = ""; String group = ""; String room = ""; String[] tks = examValidation.getAcademicYear().split("-"); Connector cn = new Connector(); String jsonPath = "http://127.0.0.1:9876/getExam?term=" + tks[0] + examValidation.getSemester(); String json = cn.getJson(jsonPath); List<AcademicYear> academicYearList = academicYearService.list(); String firstdateStr = ""; String enddateStr = ""; for (AcademicYear aY : academicYearList) { if (aY.getACAYEAR_Code().equals(examValidation.getAcademicYear())) { firstdateStr = aY.getACAYEAR_FromDate(); enddateStr = aY.getACAYEAR_ToDate(); break; } } DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy"); LocalDate firstdate = fmt.parseLocalDate(firstdateStr); LocalDate enddate = fmt.parseLocalDate(enddateStr); if (json != "") { json = "{ exams : " + json + "}"; //System.out.println(json); try { JSONObject obj = new JSONObject(json); JSONArray exams = obj.getJSONArray("exams"); for (int i = 0; i < exams.length(); ++i) { JSONObject exam = exams.getJSONObject(i); classCode = Integer.toString(exam.getInt("Classid")); courseCode = exam.isNull("CourseID") ? "" : exam.getString("CourseID"); RegularCourse rc = regularCourseService.loadByCode(courseCode); courseName = rc == null ? "" : rc.getRC_Name(); week = exam.getString("WeekName"); day = exam.getString("WeekDayName"); turn = exam.getString("TimeTable"); //date = exam.isNull("DateExam")?"":exam.getString("DateExam"); group = exam.getString("ClassGroup"); room = exam.getString("RoomID"); if (week.contains("T")) week = week.substring(1, week.length()); switch (day.toLowerCase()) { case "th hai": day = "2"; break; case "th ba": day = "3"; break; case "th t": day = "4"; break; case "th nm": day = "5"; break; case "th su": day = "6"; break; case "th by": day = "7"; break; case "ch nht": day = "8"; break; } int weekNum = Integer.parseInt(week); int dayNum = Integer.parseInt(day); date = firstdate.plusDays((weekNum - 1) * 7 + dayNum - 2).toString(fmt); room = room.replace(",", "-"); String[] tokens = turn.split(" "); //kp 1:7h 1,2,3 //kp 2: 9h30 4,5,6 //kp 3: 12h30 7,8,9 //kp 4: 15h 10,11,12 //StartTime = {0645, 0735, 0830, 0920, 1015, 1105, 1230, 1320, 1415, 1505, 1600, 1650, 2130}; //EndTime = {0730, 0820, 0915, 1005, 1100, 1150, 1345, 1405, 1500, 1550, 1645, 1735, 2130}; try { String[] subtokens = tokens[tokens.length - 1].split("-"); int startSlot = Integer.parseInt(subtokens[0]) * 3 - 2; int endSlot = Integer.parseInt(subtokens[subtokens.length - 1]) * 3; slots = Integer.toString(startSlot); for (int i1 = startSlot + 1; i1 <= endSlot; i1++) slots += "," + Integer.toString(i1); } catch (Exception e) { slots = ""; } ExamInfo objExam = new ExamInfo(classCode, courseCode, courseName, week, day, date, turn, slots, group, room); examinfos.add(objExam); } } catch (Exception e) { e.printStackTrace(); examinfos.clear(); } } int cnt = 0; for (ExamInfo ei : examinfos) { //if(cnt++==10) break; if (ei != null) { String RCE_Code = examValidation.getAcademicYear() + "-" + examValidation.getSemester() + "-" + ei.getClassCode() + "-" + ei.getGroup() + "-" + ei.getTurn() + "-" + ei.getRoom(); Exam ex = examService.loadByCode(RCE_Code); if (ex == null) { examService.save(RCE_Code, examValidation.getAcademicYear(), examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(), ei.getCourseName(), Integer.parseInt(ei.getWeek()), Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(), ei.getGroup(), ei.getRoom()); cnt++; } else { if (!((ex.getRCE_Date().equals(ei.getDate())) && (ex.getRCE_Day() == Integer.parseInt(ei.getDay())) && (ex.getRCE_Week() == Integer.parseInt(ei.getWeek())) && (ex.getRCE_Room_Code().equals(ei.getRoom())))) { examService.edit(RCE_Code, examValidation.getAcademicYear(), examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(), ei.getCourseName(), Integer.parseInt(ei.getWeek()), Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(), ei.getGroup(), ei.getRoom()); StatusMessages += "Cp nht thnh cng lp " + ex.getClass() + " nhm " + ex.getRCE_Group() + " thi\n"; } } } } StatusMessages += "Thm mi thnh cng " + cnt + " lp thi\n"; model.put("status", StatusMessages); /** * Preparing data for adding into DB */ //if(i_InsertAPaper > 0){ //model.put("status", "Successfully saved a paper: "); //model.put("status",StatusMessages); System.out.println(StatusMessages); return "redirect:" + this.baseUrl + "/cp/Exams.html"; //} } catch (Exception e) { model.put("status", "Failed to update from SIS => " + e.getMessage()); } return "cp.addExamFromSIS"; } }
From source file:vn.webapp.controller.cp.RoomsController.java
@RequestMapping(value = "executeQueryRoom", method = RequestMethod.POST) public String queryRoom(HttpServletRequest request, @Valid @ModelAttribute("queryRoom") QueryRoomValidation queryRoomValidation, BindingResult result, Map model, HttpSession session) { if (result.hasErrors()) { List<AcademicYear> academicYearList = academicYearService.list(); AcademicYear curAcadYear = academicYearService.getCurAcadYear(); List<AcademicYear> otherAcadYearList = new ArrayList<AcademicYear>(); for (AcademicYear aY : academicYearList) { if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code())) otherAcadYearList.add(aY); }/*from www. j av a 2 s. c o m*/ model.put("academicYearList", otherAcadYearList); model.put("curAcadYear", curAcadYear); return "cp.queryRoom"; } else { String academicYear = queryRoomValidation.getAcademicYear(); int maxCap = queryRoomValidation.getCapacityMax(); if (maxCap == 0) { maxCap = 300; queryRoomValidation.setCapacityMax(300); } int minCap = queryRoomValidation.getCapacityMin(); String dateString = queryRoomValidation.getDayMonthYearInput_day(); String dayString = queryRoomValidation.getDayWeekInput_day(); String weekString = queryRoomValidation.getDayWeekInput_week(); String building = queryRoomValidation.getRoomBuilding(); String slotStart = queryRoomValidation.getSlotStart(); String slotEnd = queryRoomValidation.getSlotEnd(); /* Convert date to day and week */ if (!dateString.equals("")) { //System.out.println(dateString); List<AcademicYear> academicYearList = academicYearService.list(); String firstdateStr = ""; String enddateStr = ""; for (AcademicYear aY : academicYearList) { if (aY.getACAYEAR_Code().equals(academicYear)) { firstdateStr = aY.getACAYEAR_FromDate(); enddateStr = aY.getACAYEAR_ToDate(); break; } } DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy"); LocalDate firstdate = fmt.parseLocalDate(firstdateStr); LocalDate enddate = fmt.parseLocalDate(enddateStr); LocalDate querydate = fmt.parseLocalDate(dateString); int dayNum = Days.daysBetween(firstdate, querydate).getDays(); if ((dayNum <= 0) || (Days.daysBetween(querydate, enddate).getDays() < 0)) { model.put("status", "Ngy bn nhp khng c trong nm h?c. Hy ch?n ngy hp l!"); return "cp.searchroom"; } dayString = Integer.toString(querydate.getDayOfWeek() + 1); if (dayString.equals("1")) dayString = "Ch nht"; weekString = Integer.toString(dayNum / 7 + 1); queryRoomValidation.setDayWeekInput_day(dayString); queryRoomValidation.setDayWeekInput_week(weekString); } else if (dayString.equals("") && weekString.equals("")) { model.put("status", "Khng th truy vn phng v thiu thng tin ngy thng"); return "cp.searchroom"; } try { /* Convert input week string into list of weeks */ StringConvert strConv = new StringConvert(); List<String> weeks = strConv.ExpandToListString(weekString); /* Convert input day string into list of days */ List<String> days = strConv.ExpandToListString(dayString); /* Convert input slot string into list of slots */ List<String> slots = strConv.ExpandToListString(slotStart + "-" + slotEnd); List<Rooms> roomsList = roomsService.listRooms(); List<RegularCourseTimetableInterface> RCTTI_List = regularCourseTimetableInterfaceService .loadRCTTIList(academicYear); List<Exam> examList = examService.loadExamList(academicYear); List<RoomLoan> roomLoanList = roomLoanService.listRoomLoans(); List<Rooms> freeRoomList = new ArrayList<Rooms>(); boolean isRoomAvail = true; for (Rooms room : roomsList) { isRoomAvail = true; for (RegularCourseTimetableInterface classinfo : RCTTI_List) { String stt = classinfo.getClassStatus(); if (stt != null && (stt.toLowerCase().contains("hy") || stt.toLowerCase().contains("hu"))) continue; if (!(room.getR_Code().equals(classinfo.getRoom()))) continue; else { List<String> classWeeks = strConv.ExpandToListString(classinfo.getWeek()); boolean isContainWeek = false; for (String weekstr : weeks) { if (classWeeks.contains(weekstr)) { isContainWeek = true; break; } } if (!isContainWeek) continue; if (!days.contains(Integer.toString(classinfo.getDay()))) continue; String[] tokenSlots = strConv.Expand(classinfo.getSlot()).split("[,]"); int firstSlot = Integer.parseInt(tokenSlots[0]); int lastSlot = Integer.parseInt(tokenSlots[tokenSlots.length - 1]); boolean isSlotBusy = false; for (String slot : slots) { if ((firstSlot - Integer.parseInt(slot)) * (lastSlot - Integer.parseInt(slot)) <= 0) { isSlotBusy = true; break; } } if (isSlotBusy) { isRoomAvail = false; break; } } } if (isRoomAvail) { for (Exam ex : examList) { if (!(room.getR_Code().equals(ex.getRCE_Room_Code()))) continue; else { boolean isContainWeek = false; if (weeks.contains(Integer.toString(ex.getRCE_Week()))) { isContainWeek = true; } if (!isContainWeek) continue; if (!days.contains(Integer.toString(ex.getRCE_Day()))) continue; String[] tokenSlots = ex.getRCE_Slots().split("[,]"); int firstSlot = Integer.parseInt(tokenSlots[0]); int lastSlot = Integer.parseInt(tokenSlots[tokenSlots.length - 1]); boolean isSlotBusy = false; for (String slot : slots) { if ((firstSlot - Integer.parseInt(slot)) * (lastSlot - Integer.parseInt(slot)) <= 0) { isSlotBusy = true; break; } } if (isSlotBusy) { isRoomAvail = false; break; } } } } if (isRoomAvail) { for (RoomLoan rl : roomLoanList) { if (!(room.getR_Code().equals(rl.getRL_R_Code()))) continue; else { List<String> rlWeeks = strConv.ExpandToListString(rl.getRL_Week()); boolean isContainWeek = false; for (String weekstr : weeks) { if (rlWeeks.contains(weekstr)) { isContainWeek = true; break; } } if (!isContainWeek) continue; boolean isContainDay = false; List<String> rlDays = strConv.ExpandToListString(rl.getRL_Day()); for (String daystr : days) { if (rlDays.contains(daystr)) { isContainDay = true; break; } } if (!isContainDay) continue; String[] tokenSlots = strConv.Expand(rl.getRL_Slots()).split("[,]"); int firstSlot = Integer.parseInt(tokenSlots[0]); int lastSlot = Integer.parseInt(tokenSlots[tokenSlots.length - 1]); boolean isSlotBusy = false; for (String slot : slots) { if ((firstSlot - Integer.parseInt(slot)) * (lastSlot - Integer.parseInt(slot)) <= 0) { isSlotBusy = true; break; } } if (isSlotBusy) { isRoomAvail = false; break; } } } } if (isRoomAvail) { boolean isShowed = true; if ((room.getR_Capacity() < minCap) || (room.getR_Capacity() > maxCap)) isShowed = false; if ((!building.equals("Tt c")) && (!building.equals(room.getR_Building()))) isShowed = false; if (isShowed) freeRoomList.add(room); } } System.out.println("C " + freeRoomList.size() + " phng trng!"); model.put("roomsList", freeRoomList); model.put("query", queryRoomValidation); return "cp.searchroom"; } catch (Exception e) { model.put("status", "C li xy ra trong lc truy vn:\n" + e.getMessage()); return "cp.searchroom"; } } }
From source file:vn.webapp.controller.cp.RoomsController.java
@RequestMapping(value = "add-a-room-loan", method = RequestMethod.POST) public String addARoomLoan(HttpServletRequest request, @Valid @ModelAttribute("roomLoanFormAdd") RoomLoanValidation roomLoanValidation, BindingResult result, Map model, HttpSession session) { if (result.hasErrors()) { List<AcademicYear> academicYearList = academicYearService.list(); AcademicYear curAcadYear = academicYearService.getCurAcadYear(); List<AcademicYear> otherAcadYearList = new ArrayList<AcademicYear>(); for (AcademicYear aY : academicYearList) { if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code())) otherAcadYearList.add(aY); }// w ww . j av a 2 s.co m model.put("academicYearList", otherAcadYearList); model.put("curAcadYear", curAcadYear); return "cp.addRoomLoan"; } else { String academicYear = roomLoanValidation.getAcademicYear(); String dateString = roomLoanValidation.getDayMonthYearInput_day(); String dayString = roomLoanValidation.getDayWeekInput_day(); String weekString = roomLoanValidation.getDayWeekInput_week(); String room = roomLoanValidation.getRoomCode(); String slotStart = roomLoanValidation.getSlotStart(); String slotEnd = roomLoanValidation.getSlotEnd(); /* Convert date to day and week */ List<AcademicYear> academicYearList = academicYearService.list(); String firstdateStr = ""; String enddateStr = ""; for (AcademicYear aY : academicYearList) { if (aY.getACAYEAR_Code().equals(academicYear)) { firstdateStr = aY.getACAYEAR_FromDate(); enddateStr = aY.getACAYEAR_ToDate(); break; } } DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy"); LocalDate firstdate = fmt.parseLocalDate(firstdateStr); LocalDate enddate = fmt.parseLocalDate(enddateStr); if (!dateString.equals("")) { LocalDate querydate = fmt.parseLocalDate(dateString); int dayNum = Days.daysBetween(firstdate, querydate).getDays(); if ((dayNum <= 0) || (Days.daysBetween(querydate, enddate).getDays() < 0)) { session.setAttribute("errorAddRoomLoanFwd", "Ngy bn nhp khng c trong nm h?c. Hy ch?n ngy hp l!"); return "cp.addRoomLoan"; } dayString = Integer.toString(querydate.getDayOfWeek() + 1); if (dayString.equals("8")) dayString = "Ch nht"; weekString = Integer.toString(dayNum / 7 + 1); roomLoanValidation.setDayWeekInput_day(dayString); roomLoanValidation.setDayWeekInput_week(weekString); } else if (!(dayString.equals("") || weekString.equals(""))) { try { if (dayString.equals("Ch nht")) dayString = "8"; LocalDate querydate = firstdate .plusDays(7 * (Integer.parseInt(weekString) - 1) + Integer.parseInt(dayString) - 2); roomLoanValidation.setDayMonthYearInput_day(querydate.toString()); } catch (Exception e) { roomLoanValidation.setDayMonthYearInput_day("Nhi?u ngy"); } } else { session.setAttribute("errorAddRoomLoanFwd", "Khng th thm thng tin mn phng " + roomLoanValidation.getRoomCode() + " v thiu thng tin ngy thng mn phng"); return "redirect:" + this.baseUrl + "/cp/AddRoomLoan.html"; } if (roomsService.loadByCode(room) == null) { session.setAttribute("errorAddRoomLoanFwd", "M phng " + room + " khng c trong c s d liu phng. Hy kim tra li!"); return "redirect:" + this.baseUrl + "/cp/AddRoomLoan.html"; } try { String RL_Code = roomLoanValidation.getRoomCode() + "-" + roomLoanValidation.getAcademicYear() + "-" + roomLoanValidation.getDayWeekInput_week() + "-" + roomLoanValidation.getDayWeekInput_day(); RoomLoan roomLoan = roomLoanService.loadByCode(RL_Code); if (roomLoan == null) roomLoanService.save(roomLoanValidation.getRoomCode(), roomLoanValidation.getDayWeekInput_day(), roomLoanValidation.getDayWeekInput_week(), roomLoanValidation.getAcademicYear(), roomLoanValidation.getDayMonthYearInput_day(), roomLoanValidation.getSlotStart() + "-" + roomLoanValidation.getSlotEnd(), roomLoanValidation.getNote()); return "redirect:" + this.baseUrl + "/cp/RoomLoans.html"; } catch (Exception e) { model.put("status", "You failed to edit room loan for" + roomLoanValidation.getRoomCode()); } } return "cp.addRoomLoan"; }
From source file:vn.webapp.controller.cp.RoomsController.java
@RequestMapping(value = "edit-a-room-loan", method = RequestMethod.POST) public String editARoomLoan(HttpServletRequest request, @Valid @ModelAttribute("roomLoanFormEdit") RoomLoanValidation roomLoanValidation, BindingResult result, Map model, HttpSession session) { if (result.hasErrors()) { List<AcademicYear> academicYearList = academicYearService.list(); AcademicYear curAcadYear = academicYearService.getCurAcadYear(); List<AcademicYear> otherAcadYearList = new ArrayList<AcademicYear>(); for (AcademicYear aY : academicYearList) { if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code())) otherAcadYearList.add(aY); }//from w ww . j a va2 s . c o m RoomLoan roomLoan = roomLoanService.loadByID(roomLoanValidation.getRoomLoanID()); model.put("roomLoan", roomLoan); model.put("academicYearList", otherAcadYearList); model.put("curAcadYear", curAcadYear); return "cp.editRoomLoan"; } else { String academicYear = roomLoanValidation.getAcademicYear(); String dateString = roomLoanValidation.getDayMonthYearInput_day(); String dayString = roomLoanValidation.getDayWeekInput_day(); String weekString = roomLoanValidation.getDayWeekInput_week(); String room = roomLoanValidation.getRoomCode(); String slotStart = roomLoanValidation.getSlotStart(); String slotEnd = roomLoanValidation.getSlotEnd(); /* Convert date to day and week */ List<AcademicYear> academicYearList = academicYearService.list(); String firstdateStr = ""; String enddateStr = ""; for (AcademicYear aY : academicYearList) { if (aY.getACAYEAR_Code().equals(academicYear)) { firstdateStr = aY.getACAYEAR_FromDate(); enddateStr = aY.getACAYEAR_ToDate(); break; } } DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy"); LocalDate firstdate = fmt.parseLocalDate(firstdateStr); LocalDate enddate = fmt.parseLocalDate(enddateStr); if (!dateString.equals("")) { LocalDate querydate = fmt.parseLocalDate(dateString); int dayNum = Days.daysBetween(firstdate, querydate).getDays(); int dayNum1 = Days.daysBetween(querydate, enddate).getDays(); if ((dayNum <= 0) || (Days.daysBetween(querydate, enddate).getDays() < 0)) { session.setAttribute("errorEditARoomLoanFwd", "Ngy bn nhp khng c trong nm h?c. Hy ch?n ngy hp l!"); return "redirect:" + this.baseUrl + "/cp/EditRoomLoan/" + roomLoanValidation.getRoomLoanID() + ".html"; } dayString = Integer.toString(querydate.getDayOfWeek() + 1); if (dayString.equals("8")) dayString = "Ch nht"; weekString = Integer.toString(dayNum / 7 + 1); roomLoanValidation.setDayWeekInput_day(dayString); roomLoanValidation.setDayWeekInput_week(weekString); } else if (!(dayString.equals("") || weekString.equals(""))) { try { if (dayString.equals("Ch nht")) dayString = "8"; LocalDate querydate = firstdate .plusDays(7 * (Integer.parseInt(weekString) - 1) + Integer.parseInt(dayString) - 2); roomLoanValidation.setDayMonthYearInput_day(querydate.toString()); } catch (Exception e) { roomLoanValidation.setDayMonthYearInput_day("Nhi?u ngy"); } } else { //model.put("status", "Khng th sa thng tin mn phng " + roomLoanValidation.getRoomCode()+" v thiu thng tin ngy thng mn phng"); session.setAttribute("errorEditARoomLoanFwd", "Khng th sa thng tin mn phng " + roomLoanValidation.getRoomCode() + " v thiu thng tin ngy thng mn phng. Hy sa li thng tin!"); return "redirect:" + this.baseUrl + "/cp/EditRoomLoan/" + roomLoanValidation.getRoomLoanID() + ".html"; } if (roomsService.loadByCode(room) == null) { session.setAttribute("errorEditARoomLoanFwd", "M phng " + room + " khng c trong c s d liu phng. Hy kim tra li!"); return "redirect:" + this.baseUrl + "/cp/EditRoomLoan/" + roomLoanValidation.getRoomLoanID() + ".html"; } try { String RL_Code = roomLoanValidation.getRoomCode() + "-" + roomLoanValidation.getAcademicYear() + "-" + roomLoanValidation.getDayWeekInput_week() + "-" + roomLoanValidation.getDayWeekInput_day(); RoomLoan roomLoan = roomLoanService.loadByID(roomLoanValidation.getRoomLoanID()); if (roomLoan != null) if (roomLoanValidation.getNote().isEmpty()) roomLoanValidation.setNote(roomLoan.getRL_Note()); roomLoanService.edit(roomLoanValidation.getRoomLoanID(), roomLoanValidation.getRoomCode(), roomLoanValidation.getDayWeekInput_day(), roomLoanValidation.getDayWeekInput_week(), roomLoanValidation.getAcademicYear(), roomLoanValidation.getDayMonthYearInput_day(), roomLoanValidation.getSlotStart() + "-" + roomLoanValidation.getSlotEnd(), roomLoanValidation.getNote()); return "redirect:" + this.baseUrl + "/cp/RoomLoans.html"; } catch (Exception e) { model.put("status", "You failed to edit room loan for" + roomLoanValidation.getRoomCode()); } } return "cp.editRoomLoan"; }
From source file:vn.webapp.service.AcademicYearServiceImpl.java
public AcademicYear getCurAcadYear() { List<AcademicYear> acadYearList = academicYearDAO.getList(); AcademicYear res = new AcademicYear(); LocalDate today = LocalDate.now(); LocalDate firstdate = LocalDate.now(); LocalDate enddate = LocalDate.now(); for (AcademicYear aY : acadYearList) { DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy"); DateTimeFormatter fmt1 = DateTimeFormat.forPattern("yyyy-MM-dd"); try {//www .j av a 2s.c o m firstdate = fmt.parseLocalDate(aY.getACAYEAR_FromDate()); enddate = fmt.parseLocalDate(aY.getACAYEAR_ToDate()); } catch (IllegalArgumentException e) { firstdate = fmt1.parseLocalDate(aY.getACAYEAR_FromDate()); enddate = fmt1.parseLocalDate(aY.getACAYEAR_ToDate()); } //System.out.println(aY.getACAYEAR_Code()+":"+firstdate+" --> "+enddate); if ((Days.daysBetween(firstdate, today).getDays() > 0) && (Days.daysBetween(today, enddate).getDays() > 0)) { res = aY; break; } } return res; }