标签:
如果你个方法里面有两部分相同的代码,只是个别参数不同而已,那么我们把相同的代码抽取出来作为另一个private方法,然后在原来的方法里面去调用就可以避免局部变量的问题。
1 public class DutyAutoWarningNotify extends TaskVO { 2 3 /** 4 * 5 */ 6 private static final long serialVersionUID = 4134338525795435287L; 7 8 /** 9 * {@inheritDoc} 10 */ 11 @Override 12 public void execute() throws Exception { 13 IMonCommonOperateBO monCommonOperateBO = SpringContextUtils.getBean("monCommonOperateBO", IMonCommonOperateBO.class); 14 15 String s1=monCommonOperateBO.getDictionaryItemValue("IDD_MON_SCHEDULE", "IDI_SCHEDULE_TIME1"); 16 String s2=monCommonOperateBO.getDictionaryItemValue("IDD_MON_SCHEDULE", "IDI_SCHEDULE_TIME2"); 17 String s3=monCommonOperateBO.getDictionaryItemValue("IDD_MON_SCHEDULE", "IDI_SCHEDULE_TIME3"); 18 String s4=monCommonOperateBO.getDictionaryItemValue("IDD_MON_SCHEDULE", "IDI_SCHEDULE_TIME4"); 19 Date time1=new Date(System.currentTimeMillis()+Integer.parseInt(s1));//当前时间+50分钟 20 Date time2=new Date(System.currentTimeMillis()+Integer.parseInt(s2));//当前时间+70分钟 21 Date time3=new Date(System.currentTimeMillis()+Integer.parseInt(s3));//当前时间+24小时,提前一天通知的时间 22 Date time4=new Date(System.currentTimeMillis()+Integer.parseInt(s4));//当前时间+24小时,提前一天通知的时间 23 this.sendMessage(time1, time2); 24 this.sendMessage(time3, time4); 25 } 26 27 28 private void sendMessage(Date startTime,Date endTime) throws Exception{ 29 ISchDutyDetailBO schDutyDetailBO = SpringContextUtils.getBean("schDutyDetailBO", ISchDutyDetailBO.class); 30 IMonCommonOperateBO monCommonOperateBO = SpringContextUtils.getBean("monCommonOperateBO", IMonCommonOperateBO.class); 31 IUserBI userBI = SpringContextUtils.getBean("ext_baf_userBI", IUserBI.class); 32 SchDutyDetailExample schExample = new SchDutyDetailExample(); 33 SchDutyDetailExample.Criteria schCriteria = schExample.createCriteria(); 34 StringBuffer sb = new StringBuffer(); 35 sb.append("(T_SCH_DUTY_DETAIL .IS_NOTIFY = ‘Y‘ OR EXISTS (SELECT 1 ").append("FROM t_sch_duty_table SC6 WHERE T_SCH_DUTY_DETAIL .DUTY_TABLE_ID = SC6.DUTY_TABLE_ID ") 36 .append("AND SC6.IS_NOTIFY = ‘Y‘))"); 37 String queryCondition=sb.toString(); 38 schCriteria.andOtherCondition(queryCondition); 39 schCriteria.andDutyStartTimeBetween(startTime, endTime); 40 List<SchDutyDetail> schDutyDetails = schDutyDetailBO.selectByExample(schExample); // 查询到对应班次 41 for (SchDutyDetail schDutyDetail : schDutyDetails) { 42 String userId=schDutyDetail.getDutyStaff(); 43 String noticeObj=userBI.selectUserNameById(userId); 44 if(noticeObj!=null){ 45 String noticeType = MsgConstant.MSG_NOTICE_TYPE_MSG; // 通知类型 46 String noticeMode = MsgConstant.IMSG_NOTICE_MODE_SM; // 通知方式默认为短信 47 StringBuffer dealInfoStrBuff = new StringBuffer(); 48 String time=DateFormat.getInstance().format(schDutyDetail.getDutyStartTime()); 49 dealInfoStrBuff.append(noticeObj).append("你好,你在").append(schDutyDetail.getDutyDetailId().toString()).append("班表中有") 50 .append(time).append("的班次,请提前准备,按时接班,谢谢。该提醒来自综调系统。"); 51 String noticeContent = dealInfoStrBuff.toString(); // 通知内容 52 String[] noticeArgs={noticeType,noticeMode,noticeContent,"",}; 53 UserVO userVO=userBI.selectUserByPrimaryKey(Constant.DEFAULT_USER); 54 monCommonOperateBO.sendMessage(schDutyDetail.getDutyTableId(), schDutyDetail.getTemplateId(), "0000017", schDutyDetail.getDutyDetailId().toString(), 55 noticeObj, DealConstants.OBJECTTYPE_BAF_E, userVO, noticeArgs); 56 } 57 } 58 } 59 }
标签:
原文地址:http://www.cnblogs.com/2027437606qq/p/5018579.html