美文网首页
ews-java-api学习:新建Recurring Appoi

ews-java-api学习:新建Recurring Appoi

作者: 大写K | 来源:发表于2018-04-12 22:07 被阅读0次
    /**
     * Meeting:创建重复约会
     */
    private void createRecurringAppointment(String userName, String password, String domain, String subject, String location, String startsTime, String endsTime, String recurrenceType, String recurrenceEndsDate, String body, boolean isAllDay) {
        EWS ews = new EWS();
        ExchangeService service = ews.connectEWS(userName, password, domain);
        try {
            Appointment appointment = new Appointment(service);
            // 中国标准时间
            TimeZoneDefinition tz = getTimeZoneDefinition(service, TIME_ZONE_CTT);
            appointment.setSubject(subject); // 约会标题
            appointment.setLocation(location); // 约会地点
            appointment.setBody(MessageBody.getMessageBodyFromText(body)); // 约会正文
            // 约会开始时间和结束时间
            HashMap<String, Date> times = getStartsAndEndsTime(startsTime, endsTime);
            appointment.setStart((Date) times.get("startsTime"));
            appointment.setStartTimeZone(tz);
            appointment.setEnd((Date) times.get("endsTime")); 
            appointment.setEndTimeZone(tz);
            // 约会循环类型
            Date dateRecurrenceStarts = appointment.getStart();
            Date dateRecurrenceEnds = getRecurrenceEndsDate(recurrenceEndsDate);
            Recurrence recurrences = null;
            switch(recurrenceType.toLowerCase()) {
            case "daily":
                recurrences = new Recurrence.DailyPattern(dateRecurrenceStarts, 1); // 默认interval为1天
                break;
            case "weekly":
                /**
                 * @param 重复会议开始日期
                 * @param 重复间隔为一周一次
                 * @param 重复会议发生在每周星期一
                 */
                recurrences = new Recurrence.WeeklyPattern(dateRecurrenceStarts, 1, DayOfTheWeek.Monday); // 默认每周一
                break;
            case "monthly":
                /**
                 * @param 重复会议开始日期
                 * @param 重复间隔为一月一次
                 * @param 重复会议发生在每月一号
                 */
                recurrences = new Recurrence.MonthlyPattern(dateRecurrenceStarts, 1, 1); // 默认每月一号
                break;
            case "yearly":
                /**
                     * @param 重复会议开始日期
                 * @param 重复间隔为一年一次
                     * @param 重复会议发生在每年六月一号
                 */
                recurrences = new Recurrence.YearlyPattern(dateRecurrenceStarts, Month.June, 1); // 默认每年六月一号
                break;
            default:
                System.out.println("输入无效!");
                break;
            }
            appointment.setRecurrence(recurrences);
            appointment.getRecurrence().setStartDate(dateRecurrenceStarts);
            appointment.getRecurrence().setEndDate(dateRecurrenceEnds);
            appointment.setIsAllDayEvent(isAllDay); // 是否全天事件
            appointment.save(WellKnownFolderName.Calendar, SendInvitationsMode.SendToNone);
        } catch (Exception e) {
            System.out.println("Error: Fail to create appointment!");
            e.printStackTrace();
        }
    }

    相关文章

      网友评论

          本文标题:ews-java-api学习:新建Recurring Appoi

          本文链接:https://www.haomeiwen.com/subject/vrxqkftx.html