src/com/yc/open/init/InitSystemTaks.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/ChcekPasswordHasExpiredSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/MaSendTemplateMsgSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/MaSyncLiveRoomSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/MaintainceSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/SendEmailsSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/SendWeiXinMsgSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/SendWeiXinTemplateMsgSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/init/shcedule/SpaceCheckSchedule.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/com/yc/open/ufida/schedule/UfIdaGate.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/com/yc/open/init/InitSystemTaks.java
@@ -7,8 +7,7 @@ import com.yc.factory.FactoryBean; import com.yc.multiData.MultiDataSource; import com.yc.multiData.SpObserver; import com.yc.open.init.shcedule.AttendanceReMindSchedule; import com.yc.open.init.shcedule.AttendanceSchedule; import com.yc.open.init.shcedule.*; import com.yc.open.mutual.schedule.GateEntity; import com.yc.open.mutual.schedule.Pull120201Schedule; import com.yc.open.mutual.schedule.Pull140902Schedule; @@ -62,7 +61,6 @@ log.info("初始化各系统作业(定时,推送)....."); systemTaskIfc = (SystemTaskIfc) FactoryBean.getBean("SystemTaskImpl"); for (Map.Entry<String, DataSourceEntity> entry : infoList.entrySet()) { DataSourceEntity dataSourceEntity = entry.getValue(); if (ScheduleUtils.isOnbusPlatform(dataSourceEntity)) { continue; @@ -86,9 +84,11 @@ SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId()); final List<Task> list = systemTaskIfc.getOpenAPIInfo(); if (list != null && list.size() > 0) { //先处理定时作业是多tomcat实例部署的情况 addScheduleTaks(list, dataSourceEntity,"multijob"); if ("1".equals(isStartUpSchedule)) { //设置这个是为了避免,因为集群导致重复开启定时作业,所以只在开启的系统加载 addScheduleTaks(list, dataSourceEntity); addScheduleTaks(list, dataSourceEntity,"jobs"); } else { //每个系统初始化时都需要加载OpenAPI的推送服务 addPushTaks(list, dataSourceEntity); @@ -102,16 +102,16 @@ } } } /** * 增加定时作业任务 * * @param list */ public void addScheduleTaks(List<Task> list, DataSourceEntity dataSourceEntity) { log.info(String.format("初始化%s定时作业.....", dataSourceEntity.getSystemID())); list.parallelStream().forEach(task -> { if ("jobs".equalsIgnoreCase(task.actionType)) { public void addScheduleTaks(List<Task> list, DataSourceEntity dataSourceEntity,String actipType) { log.info(String.format("初始化%s定时作业(%s)条.....", dataSourceEntity.getSystemID(),list.size())); list.stream().forEach(task -> { if (actipType.equalsIgnoreCase(task.actionType)) { log.info("作业名称:"+task.getApiName()); //生成定时执行对象 switch (task.getApiCode()) { //考勤统计 @@ -132,6 +132,31 @@ //打卡提醒 case "OP0004": create180212Schedule(dataSourceEntity, task.getApiCode()); break; //检查附件占用空间配额 case "OP0020": createScheduleTask(dataSourceEntity, task,new SpaceCheckSchedule(dataSourceEntity)); break; case "OP0027": createScheduleTask(dataSourceEntity, task,new MaintainceSchedule(dataSourceEntity)); break; case "OP0026": createScheduleTask(dataSourceEntity, task,new MaSyncLiveRoomSchedule(dataSourceEntity)); break; case "OP0025": createScheduleTask(dataSourceEntity, task,new ChcekPasswordHasExpiredSchedule(dataSourceEntity)); break; case "OP0024": createScheduleTask(dataSourceEntity, task,new MaSendTemplateMsgSchedule(dataSourceEntity)); break; case "OP0023": createScheduleTask(dataSourceEntity, task,new SendWeiXinTemplateMsgSchedule(dataSourceEntity)); break; case "OP0022": createScheduleTask(dataSourceEntity, task,new SendWeiXinMsgSchedule(dataSourceEntity)); break; case "OP0021": createScheduleTask(dataSourceEntity, task,new SendEmailsSchedule(dataSourceEntity)); break; default: break; @@ -261,17 +286,18 @@ SpObserver.setDBtoInstance("_" + dbid); final Task task = systemTaskIfc.getOpenAPI(docCode); if (task != null) { if (!"jobs".equals(task.getActionType())) { if (!"jobs".equals(task.getActionType())||!"multijob".equals(task.getActionType())) { //处理推送任务 pushTasksMap.put(dbid + "_" + task.getApiCode() + "_" + task.getAffectedFormId(), task); } else { //处理定时任务 List<Task> list = new ArrayList<>(); list.add(task); final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(dbid + ""); addScheduleTaks(list, dataSourceMap,"multijob"); String isStartUpSchedule = AttachmentConfig.get("isStartUpSchedule");//只在设置了定时任务的服务器上运行 if("1".equals(isStartUpSchedule)) { List<Task> list = new ArrayList<>(); list.add(task); final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(dbid + ""); addScheduleTaks(list, dataSourceMap); addScheduleTaks(list, dataSourceMap,task.getActionType()); } } } @@ -294,7 +320,7 @@ SpObserver.setDBtoInstance("_" + dbid); final Task task = systemTaskIfc.getOpenAPI(docCode); if (task != null) { if (!"jobs".equals(task.getActionType())) { if (!"jobs".equals(task.getActionType())||!"multijob".equals(task.getActionType())) { //处理推送任务 final Task stopTask = pushTasksMap.get(dbid + "_" + task.getApiCode() + "_" + task.getAffectedFormId()); if (stopTask != null) src/com/yc/open/init/shcedule/ChcekPasswordHasExpiredSchedule.java
New file @@ -0,0 +1,40 @@ package com.yc.open.init.shcedule; import com.yc.entity.DataSourceEntity; import com.yc.factory.FactoryBean; import com.yc.multiData.SpObserver; import com.yc.service.BaseService; import com.yc.service.user.UserAccountServiceIfc; /** * 每日检查用户密码是否过期 */ public class ChcekPasswordHasExpiredSchedule extends BaseSchedule implements Runnable { public ChcekPasswordHasExpiredSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } String dbid = dataSourceEntity.getDbId() + ""; log.info(dataSourceEntity.getSystemDescribe() + "-开始执行每日检查用户密码是否过期"); SpObserver.setDBtoInstance("_" + dbid); UserAccountServiceIfc userAccountServiceIfc = (UserAccountServiceIfc)FactoryBean.getBean("UserAccountServiceImpl") ; //检查密码是否过期 userAccountServiceIfc.doCheckHasExpired(); log.info(dataSourceEntity.getSystemDescribe() + "-每日检查用户密码是否过期完成"); } catch (InterruptedException ex) { log.info(dataSourceEntity.getSystemID() + "每日检查用户密码是否过期任务已被终止"); } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } finally { SpObserver.setDBtoInstance(); } } } src/com/yc/open/init/shcedule/MaSendTemplateMsgSchedule.java
New file @@ -0,0 +1,32 @@ package com.yc.open.init.shcedule; import com.yc.entity.DataSourceEntity; import com.yc.sdk.miniapp.action.MaSendTemplateMsg; /** * 发送微信小程序模板消息 */ public class MaSendTemplateMsgSchedule extends BaseSchedule implements Runnable { public MaSendTemplateMsgSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } log.info(dataSourceEntity.getSystemDescribe() + "-开始执行发送微信小程序模板消息"); MaSendTemplateMsg.sendTemplateMsg(dataSourceEntity, null); log.info(dataSourceEntity.getSystemDescribe() + "-发送微信小程序模板消息完成"); } catch (InterruptedException ex) { log.info(dataSourceEntity.getSystemID() + "发送微信小程序模板消息任务已被终止"); } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } } } src/com/yc/open/init/shcedule/MaSyncLiveRoomSchedule.java
New file @@ -0,0 +1,46 @@ package com.yc.open.init.shcedule; import com.yc.entity.DataSourceEntity; import com.yc.sdk.shopping.action.api.LiveRoomVideo; import me.chanjar.weixin.common.error.WxErrorException; /** * 自动拉取直播房间信息 */ public class MaSyncLiveRoomSchedule extends BaseSchedule implements Runnable { public MaSyncLiveRoomSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } log.info(dataSourceEntity.getSystemDescribe() + "-开始执行自动拉取直播房间信息"); LiveRoomVideo.refreshLiveRoom(dataSourceEntity); log.info(dataSourceEntity.getSystemDescribe() + "-自动拉取直播房间信息完成"); } catch (InterruptedException ex) { log.info(dataSourceEntity.getSystemID() + "自动拉取直播房间信息任务已被终止"); } catch (WxErrorException e) { // 61003 : {"errcode":61003,"errmsg":"component is not authorized by this account hint: [Z0HBNa01744088]"} // 48001 : {"errcode":48001,"errmsg":"api unauthorized hint: [v5RwlA02444812]"} // 61007 : {"errcode":61007,"errmsg":"api is unauthorized to component rid: 5f3f8d95-2fba1341-31496d5a"} // 9410000 {"errcode":9410000,"errmsg":"empty room list rid: 5fd81924-427cb49f-284aa824","room_info":[],"live_replay":[]} //40013 : {"errcode":40013,"errmsg":"invalid appid rid: 60dabee4-5be7bc04-76fc43f0"} //未开通直播功能,拉取失败 if (e.getError().getErrorCode() != 48001 && e.getError().getErrorCode() != 61003 && e.getError().getErrorCode() != 61007 && e.getError().getErrorCode() != 9410000 && e.getError().getErrorCode() != 40013) { log.error("正在刷新id为" + dataSourceEntity.getDbId() + "【" + dataSourceEntity.getSystemID() + "】微信小程序直播信息时出错(定时器 MaSyncLiveRoomTimer )," + this.getClass() + ",错误消息为:" + e.getMessage()); } } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } } } src/com/yc/open/init/shcedule/MaintainceSchedule.java
New file @@ -0,0 +1,35 @@ package com.yc.open.init.shcedule; import com.yc.entity.DataSourceEntity; import com.yc.factory.FactoryBean; import com.yc.multiData.MultiDataSource; import com.yc.sdk.shopping.action.api.LiveRoomVideo; import me.chanjar.weixin.common.error.WxErrorException; /** * 每晚更新已经过期的数据源 */ public class MaintainceSchedule extends BaseSchedule implements Runnable { public MaintainceSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } log.info(dataSourceEntity.getSystemDescribe() + "-开始执行每晚更新已经过期的数据源"); MultiDataSource multiDataSource = (MultiDataSource) FactoryBean.getBean("multiDataSource"); multiDataSource.refreshDataSource(dataSourceEntity!=null?dataSourceEntity.getDbId()+"":null); log.info(dataSourceEntity.getSystemDescribe() + "-每晚更新已经过期的数据源完成"); } catch (InterruptedException ex) { log.info(dataSourceEntity.getSystemID() + "每晚更新已经过期的数据源任务已被终止"); } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } } } src/com/yc/open/init/shcedule/SendEmailsSchedule.java
New file @@ -0,0 +1,66 @@ package com.yc.open.init.shcedule; import com.yc.action.mail.action.ListMailSend; import com.yc.action.mail.action.SimpleSenderMail; import com.yc.action.mail.entity.SendMailEntity; import com.yc.action.mail.service.OtherMailIfc; import com.yc.entity.DataSourceEntity; import com.yc.factory.FactoryBean; import com.yc.multiData.SpObserver; import com.yc.service.BaseService; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; /** * 定时发送邮件 */ public class SendEmailsSchedule extends BaseSchedule implements Runnable { public SendEmailsSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } String dbid = dataSourceEntity.getDbId() + ""; log.info(dataSourceEntity.getSystemDescribe() + "-开始执行定时发送邮件"); SpObserver.setDBtoInstance("_" + dbid); Date now = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置显示格式 OtherMailIfc oterIfc = (OtherMailIfc) FactoryBean.getBean("OtherMailImpl"); ListMailSend listMailSend = new ListMailSend(); int cont = oterIfc.gettables(); if (cont > 0) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); list = oterIfc.getsendMail(1, df.format(now).toString(), dataSourceEntity.getDbId()+"");// 获取自动发送的邮件 List<SendMailEntity> listmailInfo = new ArrayList<SendMailEntity>(); listmailInfo = listMailSend.getListMailSend(list, dataSourceEntity.getDbId()); // 发送邮件内容的集合 // 这个类主要来发送邮件 for (SendMailEntity mailInfo : listmailInfo) { SimpleSenderMail sms = new SimpleSenderMail(); boolean isSuccessSend = sms.sendHtmlMail(mailInfo); // 发送文体格式 if (isSuccessSend) { oterIfc.updatsendmail(mailInfo.getSenderEmail(), df.format(now).toString(), mailInfo.getDataSouroceId(), mailInfo.getId()); } } } log.info(dataSourceEntity.getSystemDescribe() + "-定时发送邮件完成"); } catch (InterruptedException ex) { log.info(dataSourceEntity.getSystemID() + "定时发送邮件任务已被终止"); } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } finally { SpObserver.setDBtoInstance(); } } } src/com/yc/open/init/shcedule/SendWeiXinMsgSchedule.java
New file @@ -0,0 +1,413 @@ package com.yc.open.init.shcedule; import com.yc.action.mail.service.ReportSetIfc; import com.yc.entity.DataSourceEntity; import com.yc.exception.ApplicationException; import com.yc.factory.FactoryBean; import com.yc.multiData.SpObserver; import com.yc.sdk.shopping.util.SettingKey; import com.yc.sdk.weixincp.action.CpServiceInit; import com.yc.sdk.weixincp.entity.ToDoUserEntity; import com.yc.sdk.weixincp.item.*; import com.yc.sdk.weixincp.service.MessagesIfc; import com.yc.sdk.weixincp.service.ToDoMsgDataIfc; import com.yc.sdk.weixincp.util.WeiXinMediaType; import com.yc.sdk.weixincp3rd.entity.App3rdEntity; import com.yc.sdk.weixincp3rd.entity.SuiteComponentAppEntity; import com.yc.sdk.weixincp3rd.entity.SuiteComponentAppSetting; import com.yc.sdk.weixinmp.entity.MpAttachmentEntity; import com.yc.service.BaseService; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpService; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 发送微信企业号消息 */ public class SendWeiXinMsgSchedule extends BaseSchedule implements Runnable { public SendWeiXinMsgSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } private static String appCode = SettingKey.ASSISTANT ; //巴士软件助手 @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } String dbid = dataSourceEntity.getDbId() + ""; log.info(dataSourceEntity.getSystemDescribe() + "-开始执行发送微信企业号消息"); SpObserver.setDBtoInstance("_" + dbid); //第三方托管写法 SuiteComponentAppEntity suiteComponentApp = SuiteComponentAppSetting.getSuiteComponentAppEntityByAppCode(appCode); if (suiteComponentApp == null) { throw new ApplicationException("未找到企业号应用AppCode【"+appCode+ "】,请检查wx-suite-component-setting.xml文件设置是否正确? "); } WxCpService wxCpService = CpServiceInit.getWxCpService(dataSourceEntity.getCorpId(),appCode) ; if (wxCpService==null) { throw new ApplicationException("未找到企业号应用AppCode【"+appCode+ "】,请检查wx-suite-component-setting.xml文件设置是否正确? 同时请检查该企业号是否被第三方正确授权?企业号CorpId【"+ dataSourceEntity.getCorpId()+"】"); } App3rdEntity app3rdEntity = CpServiceInit.getApp3rdEntity(suiteComponentApp.getSuiteId(),dataSourceEntity.getCorpId(),suiteComponentApp.getSuiteDbId()); if (app3rdEntity==null) { //System.err.println("没有找到该企业号的第三方授权信息,请重新为该企业号授权。企业号应用AppCode【"+appCode+ "】,第三方应用SuiteId【"+suiteComponentApp.getSuiteId()+"】,企业号CorpId【"+ corpEntity.getCorpId()+"】,第三方数据源【"+ suiteComponentApp.getSuiteDbId()+"】"); return ; } //发送消息 sendMessages( wxCpService, dataSourceEntity); log.info(dataSourceEntity.getSystemDescribe() + "-发送微信企业号消息完成"); } catch (InterruptedException ex) { log.error(dataSourceEntity.getSystemID() + "发送微信企业号消息任务已被终止"); } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } finally { SpObserver.setDBtoInstance(); } } private boolean sendMessages(WxCpService wxCpService,DataSourceEntity corpEntity) throws Exception { String isOnlyQueue = null ; int msgFrom = 2 ; String toUser = null ; ToDoMsgDataIfc toDoMsgData = (ToDoMsgDataIfc)FactoryBean.getBean("ToDoMsgDataImpl") ; MessagesIfc messagesIfc = (MessagesIfc)FactoryBean.getBean("MessagesImpl") ; ReportSetIfc reportSetIfc = (ReportSetIfc)FactoryBean.getBean("ReportSetImpl") ; //isOnlyQueue = 1 表示仅仅处理队列中的消息发送,用于发送被动响应消息, 被 CPCallBack.java 调用 //为空值时表示从主动推送设置表中读取最新的记录到队列中 ,用于直接使用浏览器URL调用 if (isOnlyQueue == null || "".equals(isOnlyQueue)) { msgFrom = 2 ; AllItemEntity allItem = toDoMsgData.getToDoMsgData(null,null,null,null,wxCpService.getWxCpConfigStorage().getAgentId(),corpEntity,msgFrom); List<Integer> list = toDoMsgData.saveToDoMsgData( allItem,null); //保存到数据库 String msgIds = "" ; for (int i = 0 ;list != null && list.size()>0 && i< list.size();i++) { msgIds += "," + list.get(i).toString(); } messagesIfc.savePushMsgSuccess(msgIds); //标记: 推送次数递减1 } List<ToDoUserEntity> toDoUsers = messagesIfc.getToDoUserInfo(toUser,msgFrom,wxCpService.getWxCpConfigStorage().getAgentId()) ; for (int i = 0 ; toDoUsers != null && toDoUsers.size()> 0 && i<toDoUsers.size(); i++) { ToDoUserEntity toDoUser = toDoUsers.get(i) ; //首先发送未加密的消息 AllItemEntity allItemEntity = messagesIfc.getToDoMsgs( toDoUser.getAgentId(), toDoUser.getToUser(),toDoUser.getToParty(),toDoUser.getToTag() , corpEntity.getCorpURL(),toDoUser.getSafe(),toDoUser.getMsgFrom(), corpEntity.getCorpId()); //上传附件到微信服务器,条件 : 只有 unid 而没有 mediaid 的记录 uploadAttachmentToWeiXinServer( wxCpService,corpEntity.getDbId(),allItemEntity,messagesIfc,reportSetIfc) ; toDoMsgData.sendText(wxCpService,allItemEntity.getText()); //发送text消息 toDoMsgData.sendImage(wxCpService,allItemEntity.getImage()); //image toDoMsgData.sendVoice(wxCpService,allItemEntity.getVoice()); //voice toDoMsgData.sendVideo(wxCpService,allItemEntity.getVideo()); //video toDoMsgData.sendFile(wxCpService,allItemEntity.getFile()) ; //file toDoMsgData.sendNews(wxCpService,allItemEntity.getNews()) ; //news toDoMsgData.sendMpNews(wxCpService,allItemEntity.getMpNews()) ; //mpnews } return true ; } /** * 上传只有 unid 而没有 mediaid 的附件到微信服务器,使收到消息的人可以直接查看附件内容(图片,视频,文件……) * @param allItemEntity * @param messagesIfc * @param reportSetIfc */ private void uploadAttachmentToWeiXinServer(WxCpService wxCpService, int dbId, AllItemEntity allItemEntity, MessagesIfc messagesIfc, ReportSetIfc reportSetIfc) throws Exception { List<ImageItem> imageList = allItemEntity.getImage(); String mediaType = "image" ; for (int j = 0 ;imageList != null && j < imageList.size();j++) { ImageItem imageItem = imageList.get(j) ; //上传 iReport 文件 , 因为iReport 是动态的结果集,所以每次都要执行一次 if (imageItem.getReportId() != null && ! imageItem.getReportId().equals(0) ) { Map<String,Object> mapParm = new HashMap<String,Object>() ; mapParm.put("FormID", imageItem.getFormId()) ; mapParm.put("ReportID", imageItem.getReportId()) ; mapParm.put("OutFormat", imageItem.getOutFormat()) ; mapParm.put("ireportparameters",imageItem.getiReportParameters()); File reportFile = reportSetIfc.getAttachment(dbId+"", mapParm,dbId); if (reportFile == null) continue ; mediaType = WeiXinMediaType.getMediaTypeByFileName(reportFile.getName()) ; try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, reportFile); imageItem.setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(imageItem.getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传文件素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } finally{ //临时素材 if (reportFile!=null&&reportFile.exists()&&reportFile.isFile()){ log.info("del>>dbid"+dbId+"|"+reportFile.getAbsolutePath()); reportFile.delete() ; } } } else //上传固定文件 if (imageList.get(j).getMediaId() == null || "".equals(imageList.get(j).getMediaId())) { if (imageList.get(j).getUnid() != null && !"".equals(imageList.get(j).getUnid() ) ) { List<MpAttachmentEntity> attachmentList = messagesIfc.getAttachment(imageList.get(j).getUnid()) ; //上传附件到微信服务器 for (int k = 0 ; attachmentList != null && k < attachmentList.size();k++) { InputStream is = new ByteArrayInputStream(attachmentList.get(k).getOriginalPicture()); try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, attachmentList.get(k).getFileType(), is); imageList.get(j).setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(imageList.get(j).getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传图片素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ //临时素材 if (is != null) try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } } } } // end image List<VoiceItem> voiceList = allItemEntity.getVoice(); mediaType = "voice" ; for (int j = 0 ;voiceList != null && j < voiceList.size();j++) { VoiceItem voiceItem = voiceList.get(j) ; //上传 iReport 文件 , 因为iReport 是动态的结果集,所以每次都要执行一次 if (voiceItem.getReportId() != null && ! voiceItem.getReportId().equals(0) ) { Map<String,Object> mapParm = new HashMap<String,Object>() ; mapParm.put("FormID", voiceItem.getFormId()) ; mapParm.put("ReportID", voiceItem.getReportId()) ; mapParm.put("OutFormat", voiceItem.getOutFormat()) ; mapParm.put("ireportparameters",voiceItem.getiReportParameters()); File reportFile = reportSetIfc.getAttachment(dbId+"", mapParm,dbId); if (reportFile == null) continue ; mediaType = WeiXinMediaType.getMediaTypeByFileName(reportFile.getName()) ; try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, reportFile); voiceItem.setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(voiceItem.getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传文件素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } finally{ //临时素材 if (reportFile!=null&&reportFile.exists()&&reportFile.isFile()){ log.info("del>>dbid"+dbId+"|"+reportFile.getAbsolutePath()); reportFile.delete() ; } } } else //上传固定文件 if (voiceList.get(j).getMediaId() == null || "".equals(voiceList.get(j).getMediaId())) { if (voiceList.get(j).getUnid() != null && !"".equals(voiceList.get(j).getUnid() ) ) { List<MpAttachmentEntity> attachmentList = messagesIfc.getAttachment(voiceList.get(j).getUnid()) ; //上传附件到微信服务器 for (int k = 0 ; attachmentList != null && k < attachmentList.size();k++) { InputStream is = new ByteArrayInputStream(attachmentList.get(k).getOriginalPicture()); try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, attachmentList.get(k).getFileType(), is); voiceList.get(j).setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(voiceList.get(j).getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传素材语音时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ //临时素材 if (is != null) try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } } } } // end voice List<VideoItem> videoList = allItemEntity.getVideo(); mediaType = "video" ; for (int j = 0 ;videoList != null && j < videoList.size();j++) { VideoItem videoItem = videoList.get(j) ; //上传 iReport 文件 , 因为iReport 是动态的结果集,所以每次都要执行一次 if (videoItem.getReportId() != null && ! videoItem.getReportId().equals(0) ) { Map<String,Object> mapParm = new HashMap<String,Object>() ; mapParm.put("FormID", videoItem.getFormId()) ; mapParm.put("ReportID", videoItem.getReportId()) ; mapParm.put("OutFormat", videoItem.getOutFormat()) ; mapParm.put("ireportparameters",videoItem.getiReportParameters()); File reportFile = reportSetIfc.getAttachment(dbId+"", mapParm,dbId); if (reportFile == null) continue ; mediaType = WeiXinMediaType.getMediaTypeByFileName(reportFile.getName()) ; try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, reportFile); videoItem.setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(videoItem.getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传文件素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } finally{ //临时素材 if (reportFile!=null&&reportFile.exists()&&reportFile.isFile()){ log.info("del>>dbid"+dbId+"|"+reportFile.getAbsolutePath()); reportFile.delete() ; } } } else //上传固定文件 if (videoList.get(j).getMediaId() == null || "".equals(videoList.get(j).getMediaId())) { if (videoList.get(j).getUnid() != null && !"".equals(videoList.get(j).getUnid() ) ) { List<MpAttachmentEntity> attachmentList = messagesIfc.getAttachment(videoList.get(j).getUnid()) ; //上传附件到微信服务器 for (int k = 0 ; attachmentList != null && k < attachmentList.size();k++) { InputStream is = new ByteArrayInputStream(attachmentList.get(k).getOriginalPicture()); try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, attachmentList.get(k).getFileType(), is); videoList.get(j).setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(videoList.get(j).getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传视频素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //临时素材 } } } } // end video List<FileItem> fileList = allItemEntity.getFile(); mediaType = "file" ; for (int j = 0 ;fileList != null && j < fileList.size();j++) { FileItem fileItem = fileList.get(j) ; //上传 iReport 文件 , 因为iReport 是动态的结果集,所以每次都要执行一次 if (fileItem.getReportId() != null && ! fileItem.getReportId().equals(0) ) { Map<String,Object> mapParm = new HashMap<String,Object>() ; mapParm.put("FormID", fileItem.getFormId()) ; mapParm.put("ReportID", fileItem.getReportId()) ; mapParm.put("OutFormat", fileItem.getOutFormat()) ; mapParm.put("ireportparameters",fileItem.getiReportParameters()); File reportFile = reportSetIfc.getAttachment(dbId+"", mapParm,dbId); if (reportFile == null) continue ; mediaType = WeiXinMediaType.getMediaTypeByFileName(reportFile.getName()) ; try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, reportFile); fileItem.setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(fileItem.getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传文件素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } finally{ //临时素材 if (reportFile!=null&&reportFile.exists()&&reportFile.isFile()){ log.info("del>>dbid"+dbId+"|"+reportFile.getAbsolutePath()); reportFile.delete() ; } } } else //上传固定文件 if (fileItem.getMediaId() == null || "".equals(fileItem.getMediaId())) { ; if (fileItem.getUnid() != null && !"".equals(fileItem.getUnid() ) ) { List<MpAttachmentEntity> attachmentList = messagesIfc.getAttachment(fileItem.getUnid()) ; //上传附件到微信服务器 for (int k = 0 ; attachmentList != null && k < attachmentList.size();k++) { InputStream is = new ByteArrayInputStream(attachmentList.get(k).getOriginalPicture()); try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, attachmentList.get(k).getFileType(), is); fileItem.setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(fileItem.getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传文件素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ //临时素材 if (is != null) try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } } } } // end file List<NewsItem> newsList = allItemEntity.getNews(); mediaType = "image" ; for (int j = 0 ;newsList != null && j < newsList.size();j++) { if (newsList.get(j).getMediaId() != null && ! "".equals(newsList.get(j).getMediaId())) continue ; if (newsList.get(j).getUnid() != null && !"".equals(newsList.get(j).getUnid() ) ) { List<MpAttachmentEntity> attachmentList = messagesIfc.getAttachment(newsList.get(j).getUnid()) ; //上传附件到微信服务器 for (int k = 0 ; attachmentList != null && k < attachmentList.size();k++) { InputStream is = new ByteArrayInputStream(attachmentList.get(k).getOriginalPicture()); try { WxMediaUploadResult res = wxCpService.getMediaService().upload(mediaType, attachmentList.get(k).getFileType(), is); newsList.get(j).setMediaId(res.getMediaId()) ; //回写 mediaid messagesIfc.saveMediaIdToToDoMsgs(newsList.get(j).getSeq(), res.getMediaId()) ; //回写 mediaid } catch (WxErrorException e) { System.out.println("异步上传文件素材时有错误发生,错误代码:" + e.getError().getErrorCode()+ ",错误信息:" + e.getError().getErrorMsg()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ //临时素材 if (is != null) try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } } } // end file } } src/com/yc/open/init/shcedule/SendWeiXinTemplateMsgSchedule.java
New file @@ -0,0 +1,38 @@ package com.yc.open.init.shcedule; import com.yc.entity.DataSourceEntity; import com.yc.factory.FactoryBean; import com.yc.multiData.SpObserver; import com.yc.sdk.weixinmp.action.MpSendTemplateMsg; import com.yc.service.BaseService; /** * 发送微信公众号模板消息 */ public class SendWeiXinTemplateMsgSchedule extends BaseSchedule implements Runnable { public SendWeiXinTemplateMsgSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } String dbid = dataSourceEntity.getDbId() + ""; log.info(dataSourceEntity.getSystemDescribe() + "-开始执行发送微信公众号模板消息"); SpObserver.setDBtoInstance("_" + dbid); MpSendTemplateMsg.sendTemplateMsg(dataSourceEntity); log.info(dataSourceEntity.getSystemDescribe() + "-发送微信公众号模板消息完成"); } catch (InterruptedException ex) { log.info(dataSourceEntity.getSystemID() + "发送微信公众号模板消息任务已被终止"); } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } finally { SpObserver.setDBtoInstance(); } } } src/com/yc/open/init/shcedule/SpaceCheckSchedule.java
New file @@ -0,0 +1,97 @@ package com.yc.open.init.shcedule; import com.yc.entity.DataSourceEntity; import com.yc.factory.FactoryBean; import com.yc.factory.InitBean; import com.yc.multiData.SpObserver; import com.yc.service.BaseService; import com.yc.service.schedule.CheckSpaceIfc; import com.yc.utils.FileUtil; import java.io.File; /** * 检查附件占用空间配额 */ public class SpaceCheckSchedule extends BaseSchedule implements Runnable { public SpaceCheckSchedule(DataSourceEntity dataSourceEntity) { super(dataSourceEntity); } @Override public void run() { try { if (Thread.interrupted()) { throw new InterruptedException(); } String dbid = dataSourceEntity.getDbId() + ""; SpObserver.setDBtoInstance("_" + dbid); log.info(dataSourceEntity.getSystemDescribe() + "-开始执行检查附件占用空间配额"); int id = dataSourceEntity.getDbId(); long siteSize=0; siteSize += getImageFolderSize(id); siteSize += getSmallImageFolderSize(id); siteSize += getAttachmentFolderSize(id); if(dataSourceEntity.getSiteSpaceMaxSize()>0){ if((siteSize/1048576)>dataSourceEntity.getSiteSpaceMaxSize()){ CheckSpaceIfc checkSpaceIfc = (CheckSpaceIfc)FactoryBean.getBean("CheckSpaceImpl"); checkSpaceIfc.doProcSpaceWarring(id, 2);//调用处理空间超出大小业务 } } log.info(dataSourceEntity.getSystemDescribe() + "-检查附件占用空间配额完成"); } catch (InterruptedException ex) { log.info(dataSourceEntity.getSystemID() + "检查附件占用空间配额定时任务已被终止"); } catch (Exception ex) { ex.printStackTrace(); log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); } finally { SpObserver.setDBtoInstance(); } } /** * 获得上传图片目录(文件夹)的大小 * @param dbid * @return */ private long getImageFolderSize(int dbid){ long size = 0; //如:D:\\eclipseWorkspace\\eCoWorksV2\\WebRoot\\uploads\\picture\\12 String path = InitBean.getContextAbsolutePath()+ File.separator+"uploads"+File.separator+"picture"+File.separator+dbid; File file = new File(path); size = FileUtil.getFileSize(file); return size; } /** * 获得上传小图片(缩略图)目录(文件夹)的大小 * @param dbid * @return */ private long getSmallImageFolderSize(int dbid){ long size = 0; //如:D:\\eclipseWorkspace\\eCoWorksV2\\WebRoot\\uploads\\smallpic\\12 String path = InitBean.getContextAbsolutePath()+File.separator+"uploads"+File.separator+"smallpic"+File.separator+dbid; File file = new File(path); size = FileUtil.getFileSize(file); return size; } /** * 获得上传附件目录(文件夹)的大小 * @param dbid * @return */ private long getAttachmentFolderSize(int dbid){ long size = 0; //如:D:\\eclipseWorkspace\\eCoWorksV2\\WebRoot\\uploads\\smallpic\\12 String path = InitBean.getContextAbsolutePath()+File.separator+"WEB-INF"+File.separator+"uploads"+File.separator+dbid; File file = new File(path); size = FileUtil.getFileSize(file); return size; } } src/com/yc/open/ufida/schedule/UfIdaGate.java
@@ -30,7 +30,7 @@ */ @Slf4j public class UfIdaGate extends BaseGate { private static String TASKID="OP0003";//指定130301任务ID,其他功能号也有对应的taskid private static String TASKID="OP0003";//指定130301任务ID,其他与用友相关的功能号也有用相同的taskid public void run(GateEntity gateEntity) throws Exception { try {