예제 #1
0
  public void signInOff(Long sectionId, Short signInOff, AppUser curUser, Date registerDate) {
    DutySection dutySection = (DutySection) this.dutySectionDao.get(sectionId);

    DutyRegister dutyRegister =
        this.dao.getTodayUserRegister(curUser.getUserId(), signInOff, sectionId);
    if (dutyRegister != null) {
      return;
    }

    DutyRegister register = new DutyRegister();
    register.setAppUser(curUser);
    register.setFullname(curUser.getFullname());

    Calendar regiserCal = Calendar.getInstance();
    regiserCal.setTime(registerDate);
    register.setRegisterDate(registerDate);
    register.setDayOfWeek(Integer.valueOf(regiserCal.get(7)));
    register.setInOffFlag(signInOff);

    register.setDutySection(dutySection);

    Calendar startCalendar = Calendar.getInstance();
    if (DutyRegister.SIGN_IN.equals(signInOff))
      startCalendar.setTime(dutySection.getDutyStartTime());
    else {
      startCalendar.setTime(dutySection.getDutyEndTime());
    }

    DateUtil.copyYearMonthDay(startCalendar, regiserCal);

    if (DutyRegister.SIGN_IN.equals(signInOff)) {
      if (regiserCal.compareTo(startCalendar) > 0) {
        register.setRegFlag(DutyRegister.REG_FLAG_LATE);

        Long minis =
            Long.valueOf((regiserCal.getTimeInMillis() - startCalendar.getTimeInMillis()) / 60000L);
        register.setRegMins(Integer.valueOf(minis.intValue()));
      } else {
        register.setRegFlag(DutyRegister.REG_FLAG_NORMAL);
        register.setRegMins(Integer.valueOf(0));
      }
    } else if (regiserCal.compareTo(startCalendar) < 0) {
      register.setRegFlag(DutyRegister.REG_FLAG_EARLY_OFF);

      Long minis =
          Long.valueOf((startCalendar.getTimeInMillis() - regiserCal.getTimeInMillis()) / 60000L);
      register.setRegMins(Integer.valueOf(minis.intValue()));
    } else {
      register.setRegFlag(DutyRegister.REG_FLAG_NORMAL);
      register.setRegMins(Integer.valueOf(0));
    }

    save(register);
  }
예제 #2
0
  public String my() {
    HttpServletRequest request = getRequest();
    String datafn = request.getParameter("action");

    Date startDate = null;
    Date endDate = null;
    Date reqEndDate;
    if ("month".equals(datafn)) {
      String monthday = request.getParameter("monthday");
      try {
        Date reqDate = DateUtils.parseDate(monthday, new String[] {"MM/dd/yyyy"});
        Calendar cal = Calendar.getInstance();
        cal.setTime(reqDate);

        cal.set(5, 1);

        startDate = DateUtil.setStartDay(cal).getTime();

        cal.add(2, 1);
        cal.add(5, -1);

        endDate = DateUtil.setEndDay(cal).getTime();
      } catch (Exception ex) {
        this.logger.error(ex.getMessage());
      }
    } else if ("day".equals(datafn)) {
      String day = request.getParameter("day");
      this.logger.info("day:" + day);
      try {
        Date reqDay = DateUtils.parseDate(day, new String[] {"MM/dd/yyyy"});

        Calendar cal = Calendar.getInstance();
        cal.setTime(reqDay);

        startDate = DateUtil.setStartDay(cal).getTime();

        cal.add(2, 1);
        cal.add(5, -1);

        endDate = DateUtil.setEndDay(cal).getTime();
      } catch (Exception ex) {
        this.logger.error(ex.getMessage());
      }
    } else if ("week".equals(datafn)) {
      String startweek = request.getParameter("startweek");
      String endweek = request.getParameter("endweek");
      try {
        Date reqStartWeek = DateUtils.parseDate(startweek, new String[] {"MM/dd/yyyy"});
        Date reqEndWeek = DateUtils.parseDate(endweek, new String[] {"MM/dd/yyyy"});
        Calendar cal = Calendar.getInstance();

        cal.setTime(reqStartWeek);

        startDate = DateUtil.setStartDay(cal).getTime();
        cal.setTime(reqEndWeek);

        endDate = DateUtil.setEndDay(cal).getTime();
      } catch (Exception ex) {
        this.logger.error(ex.getMessage());
      }
    } else if ("period".equals(datafn)) {
      String start = request.getParameter("start");
      String end = request.getParameter("end");
      try {
        Date reqStartDate = DateUtils.parseDate(start, new String[] {"MM/dd/yyyy"});
        reqEndDate = DateUtils.parseDate(end, new String[] {"MM/dd/yyyy"});

        Calendar cal = Calendar.getInstance();

        cal.setTime(reqStartDate);

        startDate = DateUtil.setStartDay(cal).getTime();

        cal.setTime(reqEndDate);

        endDate = DateUtil.setEndDay(cal).getTime();
      } catch (Exception ex) {
        this.logger.info(ex.getMessage());
      }
    } else {
      this.jsonString = "{success:false,errors:'there's enough arguments to generate data'}";
    }

    StringBuffer sb = new StringBuffer();

    List<CalendarPlan> planList =
        this.calendarPlanService.getByPeriod(ContextUtil.getCurrentUserId(), startDate, endDate);

    sb.append("{success:true,totalCount:").append(planList.size()).append(",records:[");

    for (CalendarPlan plan : planList) {
      sb.append("{id:'").append(plan.getPlanId()).append("',");

      String subject = plan.getContent();
      if (subject.length() > 12) {
        subject = subject.substring(1, 12) + "...";
      }

      Date endTime = plan.getEndTime();
      if (endTime == null) {
        Calendar curCal = Calendar.getInstance();
        curCal.add(1, 50);
        endTime = curCal.getTime();
      }

      Date startTime = plan.getStartTime();
      if (this.start == null) {
        Calendar curCal = Calendar.getInstance();
        startTime = curCal.getTime();
      }

      sb.append("subject:'").append(StringUtil.convertQuot(subject)).append("',");
      sb.append("description:'").append(StringUtil.convertQuot(plan.getContent())).append("',");
      sb.append("startdate:'").append(DateUtil.formatEnDate(startTime)).append("',");
      sb.append("enddate:'").append(DateUtil.formatEnDate(endTime)).append("',");
      sb.append("color:'").append(plan.getColor()).append("',");
      sb.append("parent:'0',");
      sb.append("priority:'").append(plan.getUrgent()).append("'},");
    }

    if (planList.size() > 0) {
      sb.deleteCharAt(sb.length() - 1);
    }
    sb.append("]}");

    this.jsonString = sb.toString();
    return "success";
  }