Package Com.paic.pad.info.monitor.res.biz.services.impl;import Java.text.simpledateformat;import Java.util.arraylist;import Java.util.date;import Java.util.list;import Java.util.map;import Org.apache.commons.lang.stringutils;import Org.apache.commons.lang.time.stopwatch;import Org.apache.commons.logging.log;import Org.apache.commons.logging.logfactory;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.component;import Org.springframework.transaction.annotation.transactional;import Com.paic.pad.info.common.biz.services.bussinessservices;import Com.paic.pad.info.common.biz.services.commsysparamservice;import Com.paic.pad.info.common.biz.services.workcalendarservice;import Com.paic.pad.info.common.dto.BussinessDTO; Import Com.paic.pad.info.common.utils.commonutils;import Com.paic.pad.info.common.utils.dateutils;import Com.paic.pad.info.common.utils.systemconstant;import Com.paic.pad.info.monitor.res.biz.services.messageboardquartzservice;impORT Com.paic.pad.info.tmr.board.biz.dao.po.msgboardinstructorpo;import Com.paic.pad.info.tmr.board.biz.services.msgboardinstructorservices;import Com.paic.pad.info.tmr.board.biz.services.msgboardregistrationservices;import Com.paic.pad.info.tmr.board.biz.services.msgboardscheduleservices;import Com.paic.pad.info.tmr.board.biz.services.schedulehistoryservices;import Com.paic.pad.info.tmr.board.dto.msgboardinstructordto;import Com.paic.pad.info.tmr.board.dto.msgboardscheduledto;import Com.paic.pad.info.tmr.board.dto.ScheduleHistoryDTO; Import Com.paic.pad.info.tmr.message.biz.dao.po.messagepo;import Com.paic.pad.info.tmr.message.biz.services.messageservice;import Com.paic.pad.info.tmr.message.dto.MessageDTO; Import Com.paic.pafa.app.biz.service.baseservice;import com.paic.pafa.app.biz.service.businessserviceexception;/ * * Message Board Timer task * * @author hailei015 * */@Component ("Messageboardquartzservice") public class Messageboardquartzserviceimpl Extends Baseservice implements MessageboardquartzseRvice {Private final Log logger = Logfactory.getlog (This.getclass ()); @Autowiredprivate Commsysparamservice Commsysparamservice, @Autowiredprivate msgboardregistrationservices msgboardregistrationservices;@ Autowiredprivate workcalendarservice Workcalendarservice, @Autowiredprivate schedulehistoryservices Schedulehistoryservices, @Autowiredprivate msgboardscheduleservices msgboardscheduleservices; @Autowiredprivate Msgboardinstructorservices msgboardinstructorservices, @Autowiredprivate messageservice messageservice;@ Autowiredprivate bussinessservices bussinessservices;private Final SimpleDateFormat format = new SimpleDateFormat (" Yyyy-mm-dd "); @Overridepublic string Executemsgboardscheduleandreminddisablejob () {String message =" "; try {list< bussinessdto> list = bussinessservices.getallbussinesslist (); message = Executemsgboardscheduleandreminddisablejobbyadmin (list);} catch (Exception e) {message = "Query line of Business exception"; Logger.error ("Executemsgboardscheduleandremindjob: Query Line of Business exception", e);} Return message;} /** * Give a date to determine if it has a schedule, and if not, arrange the smallest date object into this class * * @param date * @throws businessserviceexception */private void msgboardsched Ulebydate (string date, String bizseries) throws Exception {Boolean canschedule = true;//default requires scheduling msgboardscheduledto DTO = m Sgboardscheduleservices.getmsgboardschedulebydate (date, bizseries); if (dto! = null) {//If this day has already been scheduled if ( Dto.getisdisable (). Equals (Msgboardinstructorpo.disable_no)) {canschedule = False;logger.info (" Msgboardschedulebydate: Date "+ Date +" already has a counselor, no scheduling required! ");}} if (canschedule) {String mindate = msgboardscheduleservices.getminmsgboardscheduledate (bizseries); Stringutils.isnotempty (MinDate)) {Msgboardscheduledto toscheduledto = Msgboardscheduleservices.getmsgboardschedulebydate (MinDate, bizseries); Toscheduledto.setscheduledate ( Dateutils.todate (date)); Msgboardscheduleservices.updatemsgboardschedule (toscheduledto); Msgboardinstructordto msgdto = new Msgboardinstructordto (); Msgdto.setumid (Toscheduledto.getumid ()); Msgdto.setisdisable (Msgboardinstructorpo.diSABLE_NO); Msgboardinstructorservices.updatemsgboardinstructor (msgdto); Logger.info ("MsgBoardScheduleByDate: Success will be" + msgdto.getumid () + "schedule with last Shift date:" + MinDate + ", New schedule:" + Date ";}} /** * Perform message board Scheduled tasks according to line of Business * * @param bizseries */@Transactionalprivate string executemsgboardjobs (String bizseries) throws Exc eption {String message = "execution succeeded!"; /Get current date string today = dateutils.gettodaydate (format); String yesterday = Dateutils.getdate (today,-1, format);//Today's duty Record object Msgboardscheduledto DTO = Msgboardscheduleservices.getmsgboardschedulebydate (Yesterday, bizseries); if (dto! = null) {//If today is Friday then NextDay should not be Saturday and should be a working day (such as Monday is correct) Date Nextworkday = Workcalendarservice.getseqworkdaybypramdate (today, bizseries); Nextworkday! = null) {today = dateutils.tostring (nextworkday);} else {message = "execution failed, unable to get next business day!"; Logger.error ("Executemsgboardjobs:" + message); return message;} /************************ execution Content 1. We're done today. Insert a running record **************************************/schedulehistorydto Schedulehistorydto = new Schedulehistorydto (); Schedulehistorydto.setscheduledate (Dto.getscheduledate ()); Schedulehistorydto.setumid (Dto.getumid ()); Schedulehistorydto.setloginuser ("Msgboardjob"); Schedulehistoryservices.insertschedulehistory (schedulehistorydto); Logger.info ("Executemsgboardjobs: Insert Successfully" + Yesterday + "On duty record, counselor:" + Dto.getumid ());/************************ execution Content 2. The change of the day on the watch is disabled and can be re-scheduled status ******************* /msgboardinstructordto msgboardinstructordto = new Msgboardinstructordto (); Msgboardinstructordto.setisdisable (Msgboardinstructorpo.disable_yes); Msgboardinstructordto.setumid (dto.getUmId ()); Msgboardinstructorservices.updatemsgboardinstructor (msgboardinstructordto);// Put all those who were not on duty before today to be on duty msgboardinstructorservices.changeinstructordisablebeforetoday (bizseries); Logger.info (" Executemsgboardjobs: Successfully modified "+ Yesterday +" instructor "+ dto.getumid () +" on duty ");/************************ perform content 3. Scheduling ********** /integer Personcount = Msgboardscheduleservices.getmsgboardSchedulecount (bizseries); String oneworkday = Getworkdayafter (1, yesterday, bizseries);//Drain after 1 days after today string twoworkday = Getworkdayafter (1, t Oday, bizseries); Reminder 1 day Reminder row 2 days after the class string threeworkday = Getworkdayafter (3, Yesterday, bizseries);//Drain after today's 3 days after the weekday string fourwork Day = Getworkdayafter (3, today, bizseries); Support 3-day reminder//row 4 days after the class if ((Personcount! = null) && (Personcount.intvalue () > 0)) {//number to more than 4 people to go 3 days reminder process and 1 day reminder if (Perso Ncount.intvalue () >= 4) {this.msgboardschedulebydate (oneworkday, bizseries); This.msgboardschedulebydate ( Twoworkday, bizseries); This.msgboardschedulebydate (Threeworkday, bizseries); This.msgboardschedulebydate ( Fourworkday, bizseries);} The number of people less than 4 is greater than 2 persons only walking 1 days to remind else if ((Personcount.intvalue () <= 3) && (Personcount.intvalue () >= 2)) {This.msgboards Chedulebydate (Oneworkday, bizseries); This.msgboardschedulebydate (Twoworkday, bizseries);} If only 1 people can only schedule, unable to remind else if (personcount.intvalue () = = 1) {this.msgboardschedulebydate (oneworkday, BizSeries);}} else {message = "There is currently no message board Counselor, cannot schedule!" "; Logger.info (" Executemsgboardjobs: "+ message);} /************************ performing content 4. Message reminder **************************************/string SYSNAMESTR = Commsysparamservice.queryparamvaluebybizseriesandparamkey (Bizseries, Systemconstant.message_board_sysadmin_name ); String sysName = Stringutils.isempty (sysnamestr)? "Unknown": sysnamestr; String systelstr = Commsysparamservice.queryparamvaluebybizseriesandparamkey (bizseries, SystemConstant.MESSAGE_ Board_sysadmin_tel); String Systel = Stringutils.isempty (systelstr)? "Unknown": systelstr; Messagedto messagedto = new Messagedto () messagedto.setmessagetitle ("Message Board Counselor Reminder"); Messagedto.setmessagetype ( Messagepo.message_board); Messagedto.setsource (MESSAGEPO.MESSAGE_SOURCE_TMR); messagedto.setstatus (0); Messagedto.setmessagefrom (Messagepo.message_sys_from); Messagedto.setsubmitdate (new Date ()); MessageDTO.setUmId (" Padinfodata "); Msgboardscheduledto Msgdtothree = msgboardscheduleservices.getmsgboardschedulebydate (FourWorkDay, BiZSeries); if (msgdtothree! = null) {Messagedto.setmessageto (Msgdtothree.getumid ()); Messagedto.setmessagecontent ( Fourworkday + "You will serve as the message board on duty, if the day of leave please contact the administrator in advance" + SysName + "(Contact:" + Systel + ") arrangement adjustment. "); Messageservice.addmessage (messagedto); Logger.info (" Executemsgboardjobs: Reminder after three days of successful delivery "+ Msgdtothree.getumid () +" Duty Date: "+ Fourworkday);} Msgboardscheduledto Msgdtotomorrow = msgboardscheduleservices.getmsgboardschedulebydate (TwoWorkDay, bizSeries); Msgdtotomorrow = null) {Messagedto.setmessageto (Msgdtotomorrow.getumid ()); Messagedto.setmessagecontent ( Twoworkday + "You will serve as the message board on duty, if the day of leave please contact the administrator in advance" + SysName + "(Contact:" + Systel + ") arrangement adjustment. "); Messageservice.addmessage (messagedto); Logger.info (" Executemsgboardjobs: Reminders sent successfully after one day "+ Msgdtotomorrow.getumid () + "Duty Date:" + Twoworkday);}} else {logger.info ("Executemsgboardjobs: There is no shift on duty yesterday!");} return message;} /** * Working date (non-working day automatic filtering) for a given date after the specified number of days for this date is returned next Tuesday * * @param today * @return * @throws businessserviceexceptio n */private String getworkdayafter (int Laterday, String today, String umbizseries) throws Businessserviceexception {string threeday = null;for (int i = 1; I < ; = Laterday; i++) {String oneday = Dateutils.getdate (today, +1, format); today = Dateutils.tostring ( Workcalendarservice.getseqworkdaybypramdate (Oneday, umbizseries)); threeday = Today;} return threeday;} @Overridepublic string executemsgboardscheduleandreminddisablejobbyadmin (list<bussinessdto> List) {string message = "message board scheduling"; Boolean isgetlock = false;try {//N for the moment no one executes y means that it is already executing if N can be changed to Y to prove that no one is currently executing. The default execution will change to n//N to y if the number of modified bars is greater than 0 indicates success, no one currently int updatedcount = Commsysparamservice.updateparamvaluebyparamkey ( systemconstant.message_schedule_quartz_is_started, systemconstant.no, systemconstant.yes, NULL); Boolean isquartzstarted = (updatedcount <= 0); if (isquartzstarted) {message = "is already executing and cannot be re-executed! "; Logger.info (" Executemsgboardscheduleandremindjob: "+ message); return message;} else {Isgetlock = true;} StopWatch watch = new StopWatch (); Watch.start (); Logger.info ("ExecutemsgboardsCheduleandremindjob: Task Start "), if (Commonutils.listnotnull (list)) {//To determine if the Business Line Message Board Counselor function is turned on (Y: Enabled or N: disabled) map<string, string> map = Commsysparamservice.queryparamvaluesmapbyparamkey (systemconstant.enable_fun_instructor); Logger.info ("Executemsgboardscheduleandremindjob: the line of business that can currently be executed is (" + list.size () + ")"); for (int i = 0; I < list.size (); i++) {Bussinessdto bussinessdto = List.get (i); String bizseri = Bussinessdto.getbizseries (); String enablefuninstructor = Map.get (bizseri);//function switch on if (Stringutils.isnotempty (enablefuninstructor) && Enablefuninstructor.equals (Systemconstant.yes)) {try {//Get last task execution date string lastquartzdate = Commsysparamservice.queryparamvaluebybizseriesandparamkeywithoutcache (Bizseri, SystemConstant.MESSAGE_SCHEDULE_ Quartz_deal_time); lastquartzdate = Stringutils.isnotempty (lastquartzdate)? Lastquartzdate: "2000-01-01";//Gets the current date string today = dateutils.gettodaydate (format); Boolean isdatalatest = ( Lastquartzdate.compareto (today) >= 0); if (isdatalatest) {message = message + Line of business ["+ Bizseri +"] has been scheduled and cannot be executed repeatedly! \ n "; Logger.info (" Executemsgboardscheduleandremindjob: "+ message); continue;} Logger.info ("Executemsgboardscheduleandremindjob: Start line of Business [" + Bizseri + "] schedules"); String bizmsg = This.executemsgboardjobs (bizseri); message = message + "\ n [" + Bizseri + "] schedules" + bizmsg;logger.info ("exec Utemsgboardscheduleandremindjob: Complete line of business ["+ Bizseri +"] scheduling "); Commsysparamservice.updateparamvaluebyparamkey ( Systemconstant.message_schedule_quartz_deal_time, NULL, today, BUSSINESSDTO.GETBUSSINESSID ()); Logger.info (" Executemsgboardscheduleandremindjob: Line of Business ["+ Bizseri +"] execution date updated to "+ Today +" Success ");} catch (Exception e) {message = message + "\ n [" + Bizseri + "] Scheduled exception"; Logger.error ("Executemsgboardscheduleandremindjob: Line of Business ["+ Bizseri +"] Scheduling exception ", e);}} else {message = message + ' \ n [' + Bizseri + '] shift function switch is not turned on! " ;}}} Wait 5 minutes for the processing to prevent the other servers from repeating Thread.Sleep (5 *); Watch.stop (); Logger.info ("Executemsgboardscheduleandremindjob: The task is completed and the execution takes time: "+ watch.gettime ());} catch (EXception e) {message = ' execution of an exception occurred! Execution failed! Please contact the administrator! "; Logger.error ("Executemsgboardscheduleandreminddisablejob:" + message, e);} Finally {//after all tasks have been executed, open the switch so that the next time you can go to execute try {if (isgetlock) {Commsysparamservice.updateparamvaluebyparamkey ( systemconstant.message_schedule_quartz_is_started, Systemconstant.yes, systemconstant.no, NULL);}} catch (Businessserviceexception e) {logger.error ("Executemsgboardscheduleandremindjob: Reset Message_schedule_quartz_ Is_started failed ", e);}} return message;}}
Message board Scheduled Tasks