In the task management process, the process is initiated through a template, which is a persistence of the anthropomorphic document and can be used repeatedly to initiate the task management process. There are two methods for initiating a template-based process: manual initiation process and automatic initiation process. This article involves the automatic initiation process.
The template customization process first specifies whether to manually or automatically launch the process, and then specifies the launch cycle, specifying the scheduled completion time and reminder time of the task. There are five launch cycles for the template: weekly, monthly, quarterly, annual, and scheduled. The reminder time refers to the number of days before the scheduled completion time. On the day of the reminder time, the process specified by this template is initiated, and the recipient of the task is also described in an email.
The Automatic Execution program starts to run at every day. It checks all templates, based on the planned completion time (date) and reminder time (days) determines whether the day when the automatic execution program runs is the date of the launch template process specified by the reminder time and planned completion time. If yes, the launch process sends a descriptive email.
Specify a specific day in the corresponding category under the template cycle. The automatic execution program will initiate the corresponding process for the template on the day of each cycle. In the middle, the week refers to Monday to Sunday, the month refers to the 1 to 31, and the quarter refers to the first quarter to the fourth quarter (the first quarter is one day from 1 to March, the second quarter is one day between 4 and June ...), The year is from January 1, January 1-12 to 31, and the timing refers to any specific time, for example, 2012-5-31.
Comparison of the five types of cycles can be divided into two types: weekly and monthly. Instead of specifying the date of completion of the specific plan, you can specify the number of weeks or months, you need to manually calculate the number, and specify the remaining three. The first four can be said to be the real cycle, while the timing is a specific time, that is, it will only be executed once. The first four scheduled completion times refer to whether they are in the current cycle or the next cycle, plus the reminder time to calculate the reminder date, and determine whether the template needs to be initiated on the day when the automatic program runs. The code for this description is as follows:
Import Java. text. parseexception; import Java. text. simpledateformat; import Java. util. calendar; import Java. util. date; import Java. util. iterator; import Java. util. list; Public void dotask () throws vwexception {date currentdate = new date (); simpledateformat SDF = new simpledateformat ("yyyy-mm-dd"); try {currentdate = SDF. parse (SDF. format (currentdate);} catch (parseexception E1) {// todo auto-generated cat Ch blocke1.printstacktrace ();} calendar = calendar. getinstance (); Calendar. settime (currentdate); system. out. println ("current time:" + calendar. get (calendar. year) + "year" + (calendar. get (calendar. month) + 1) + "month" + calendar. get (calendar. day_of_month) + "day week" + (calendar. get (calendar. day_of_week) = 1 )? 7: (calendar. Get (calendar. day_of_week)-1); List <tasksupervision> tasksupervisionlist = tasksupervisionbusinessservice. getall (); If (tasksupervisionlist! = NULL) {iterator <tasksupervision> iterator = tasksupervisionlist. iterator (); While (iterator. hasnext () {calendar. settime (currentdate); tasksupervision next = iterator. next (); string period = next. getperiod (); system. out. println ("cycle:" + period); If ("Week ". week signorecase (period) {// Today is the day of the week int dayofweek = calendar ar. get (calendar. day_of_week); string plancompletedate = next. getweekplancompletedate (); int dividing = 0; If ("Monday ". equals (plancompletedate) {// Monday is the second day of the week dividing = 2;} else if ("Tuesday ". equals (plancompletedate) {dividing = 3;} else if ("Wednesday ". equals (plancompletedate) {dividing = 4;} else if ("Thursday ". equals (plancompletedate) {dividing = 5;} else if ("Friday ". equals (plancompletedate) {dividing = 6;} else if ("Saturday ". equals (plancompletedate) {dividing = 7;} else if ("Sunday ". equals (plancompletedate) {// Sunday is the first day of the week dividing = 1;} // If the week number of the completion date is after the week number of today, this week is the planned completion date, if the week number is earlier than the week number, the completion date of the Week will be calculated by the calculator to remind int interval = 0; If (dividing> = dayofweek) {interval = dividing-dayofweek; // The scheduled completion date is calendar. add (calendar. date, interval);} else {interval = dayofweek-dividing; // the scheduled completion date of the calendar. add (calendar. date, 7-interval);} // gets the number of days of reminder, and calculates the reminder date int remindertime = next. getremindertime (); Calendar. add (calendar. date,-remindertime); int dayofweektoplan = calendar. get (calendar. day_of_week); // if today is the reminder time, the email will remind try {date reminderdate = SDF. parse (SDF. format (calendar. gettime (); If (reminderdate. gettime () = currentdate. gettime () {}} catch (parseexception e) {// todo auto-generated catch blocke. printstacktrace () ;}} else if ("Monthly ". equalsignorecase (period) {// The Day of the day int dayofmonth = calendar ar. get (calendar. day_of_month); // The date of the planned completion date. String plancompletedate = next. getmonthplancompletedate (); int intplancomday = integer. parseint (plancompletedate); int interval = 0; If (intplancomday> = dayofmonth) {interval = intplancomday-dayofmonth; // the planned completion date calendar ar. add (calendar. date, interval);} else {interval = dayofmonth-intplancomday; // the scheduled completion date calendar. add (calendar. month, 1); Calendar. add (calendar. date,-interval);} // obtain the number of days of reminder, and calculate the reminder date int remindertime = next. getremindertime (); Calendar. add (calendar. date,-remindertime); // if today is the reminder time, initiate the process and send an email to remind try {date reminderdate = SDF. parse (SDF. format (calendar. gettime (); If (reminderdate. gettime () = currentdate. gettime () {}} catch (parseexception e) {// todo auto-generated catch blocke. printstacktrace () ;}} else if ("quarter ". required signorecase (period) {// check whether an email needs to be sent. Try {// reminder days int remindertime = next. getremindertime (); // The first quarter string plancompletedate = next. getfirstquarterplancompletedate (); Date reminderdate = NULL; // get the reminder time calendar calendarmonth = calendar. getinstance (); calendarmonth. settime (SDF. parse (calendar. get (calendar. year) + "-" + plancompletedate); calendarmonth. add (calendar. date,-remindertime); reminderdate = SDF. parse (SDF. format (calendarmonth. gettime (); // initiate the process and email notification if (currentdate. gettime () = reminderdate. gettime () {}// the second quarter plancompletedate = next. getsecondquartercompletedate (); reminderdate = NULL; // obtain the reminder time calendarmonth = calendar ar. getinstance (); calendarmonth. settime (SDF. parse (calendar. get (calendar. year) + "-" + plancompletedate); calendarmonth. add (calendar. date,-remindertime); reminderdate = SDF. parse (SDF. format (calendarmonth. gettime (); // initiate the process and email notification if (currentdate. gettime () = reminderdate. gettime () {}// plancompletedate = next in the third quarter. getthirdquarterplancompletedate (); reminderdate = NULL; // obtain the reminder time calendarmonth = calendar ar. getinstance (); calendarmonth. settime (SDF. parse (calendar. get (calendar. year) + "-" + plancompletedate); calendarmonth. add (calendar. date,-remindertime); reminderdate = SDF. parse (SDF. format (calendarmonth. gettime (); // initiate the process and email notification if (currentdate. gettime () = reminderdate. gettime () {}// plancompletedate = next in the fourth quarter. getforthquarterplancompletedate (); reminderdate = NULL; // obtain the reminder time calendarmonth = calendar ar. getinstance (); calendarmonth. settime (SDF. parse (calendar. get (calendar. year) + "-" + plancompletedate); calendarmonth. add (calendar. date,-remindertime); reminderdate = SDF. parse (SDF. format (calendarmonth. gettime (); // initiate the process and email notification if (currentdate. gettime () = reminderdate. gettime () {}} catch (parseexception e) {e. printstacktrace () ;}} else if ("year ". required signorecase (period) {// check whether an email needs to be sent. Try {string plancompletedate = next. getyearplancompletedate (); int remindertime = next. getremindertime (); Date reminderdate = NULL; // obtain the reminder time calendar calendarmonth = calendar. getinstance (); calendarmonth. settime (SDF. parse (calendar. get (calendar. year) + "-" + plancompletedate); calendarmonth. add (calendar. date,-remindertime); reminderdate = SDF. parse (SDF. format (calendarmonth. gettime (); // initiate the process and email notification if (currentdate. gettime () = reminderdate. gettime () {}} catch (parseexception e) {e. printstacktrace () ;}} else if ("scheduled ". required signorecase (period) {// nothing // check whether an email needs to be sent. Try {string plancompletedate = next. gettimeplancompletedate (); int remindertime = next. getremindertime (); Date reminderdate = NULL; // obtain the reminder time calendar calendarmonth = calendar. getinstance (); calendarmonth. settime (SDF. parse (plancompletedate); calendarmonth. add (calendar. date,-remindertime); reminderdate = SDF. parse (SDF. format (calendarmonth. gettime (); // initiate the process and email notification if (currentdate. gettime () = reminderdate. gettime () {}} catch (parseexception e) {e. printstacktrace ();}}}}}
Periodic execution, periodic category, planned completion time, and reminder time constitute this small requirement, the ambiguity of the business meaning of the planned completion time and reminder time leads to repeated code modifications. These problems can be further clarified, or the requirements or algorithms cover all situations, continue to understand later.