old mode 100644
new mode 100755
| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.annotation.Java110Synchronized; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.core.factory.WechatFactory; |
| | | import com.java110.core.smo.ISaveTransactionLogSMO; |
| | | import com.java110.dto.RoomDto; |
| | | import com.java110.dto.app.AppDto; |
| | | import com.java110.dto.community.CommunityDto; |
| | | import com.java110.dto.logSystemError.LogSystemErrorDto; |
| | | import com.java110.dto.notice.NoticeDto; |
| | | import com.java110.dto.owner.OwnerAppUserDto; |
| | | import com.java110.dto.owner.OwnerRoomRelDto; |
| | |
| | | import com.java110.intf.user.IOwnerAppUserInnerServiceSMO; |
| | | import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO; |
| | | import com.java110.job.quartz.TaskSystemQuartz; |
| | | import com.java110.po.logSystemError.LogSystemErrorPo; |
| | | import com.java110.po.transactionLog.TransactionLogPo; |
| | | import com.java110.service.smo.ISaveSystemErrorSMO; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.utils.constant.WechatConstant; |
| | | import com.java110.utils.util.DateUtil; |
| | | import com.java110.utils.util.ExceptionUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | @Autowired |
| | | private RestTemplate outRestTemplate; |
| | | |
| | | @Autowired |
| | | private ISaveSystemErrorSMO saveSystemErrorSMOImpl; |
| | | |
| | | //模板信息推送地址 |
| | | private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="; |
| | | private static String getUser = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN"; |
| | |
| | | try { |
| | | publishMsg(taskDto, communityDto); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("推送消息失败", e); |
| | | } |
| | | } |
| | |
| | | try { |
| | | doSentWechat(tmpNotice, templateId, accessToken, weChatDto); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("通知异常", e); |
| | | } |
| | | } |
| | |
| | | |
| | | private void doSentWechat(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) throws Exception { |
| | | |
| | | Date startTime = DateUtil.getDateFromString(noticeDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_A); |
| | | Date nowTime = DateUtil.getCurrentDate(); |
| | | if (startTime.getTime() > nowTime.getTime()) { //还没有到时间 |
| | | return; |
| | | } |
| | | // Date startTime = DateUtil.getDateFromString(noticeDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_A); |
| | | // Date nowTime = DateUtil.getCurrentDate(); |
| | | // if (startTime.getTime() > nowTime.getTime()) { //还没有到时间 |
| | | // return; |
| | | // } |
| | | |
| | | |
| | | String objType = noticeDto.getObjType(); |
| | | |
| | | switch (objType) { |
| | | case NoticeDto.OBJ_TYPE_COMMUNITY: |
| | | case NoticeDto.OBJ_TYPE_ALL: |
| | | sendAllOwner(noticeDto, templateId, accessToken, weChatDto); |
| | | break; |
| | | case NoticeDto.OBJ_TYPE_FLOOR: |
| | |
| | | case NoticeDto.OBJ_TYPE_ROOM: |
| | | sendRoomOwner(noticeDto, templateId, accessToken, weChatDto); |
| | | break; |
| | | case NoticeDto.OBJ_TYPE_COMMUNITY: |
| | | sendCommunityOwner(noticeDto, templateId, accessToken, weChatDto); |
| | | break; |
| | | } |
| | | |
| | | NoticeDto tmpNoticeDto = new NoticeDto(); |
| | |
| | | tmpNoticeDto.setState(NoticeDto.STATE_FINISH); |
| | | noticeInnerServiceSMOImpl.updateNotice(tmpNoticeDto); |
| | | |
| | | } |
| | | |
| | | private void sendCommunityOwner(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) { |
| | | OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto(); |
| | | ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT); |
| | | ownerAppUserDto.setCommunityId(noticeDto.getCommunityId()); |
| | | List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto); |
| | | doSend(ownerAppUserDtos, noticeDto, templateId, accessToken, weChatDto); |
| | | } |
| | | |
| | | private void sendFloorOwner(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) { |
| | |
| | | private void doSend(List<OwnerAppUserDto> ownerAppUserDtos, NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) { |
| | | String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL") + "/#/pages/notice/detail/detail?noticeId="; |
| | | ResponseEntity<String> responseEntity = null; |
| | | String sendTemplate = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN,WechatConstant.SEND_TEMPLATE_URL); |
| | | if(StringUtil.isEmpty(sendTemplate)){ |
| | | sendTemplate = sendMsgUrl; |
| | | } |
| | | for (OwnerAppUserDto appUserDto : ownerAppUserDtos) { |
| | | Date startTime = DateUtil.getCurrentDate(); |
| | | PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage(); |
| | |
| | | data.setKeyword3(new Content(StringUtil.delHtmlTag(noticeDto.getContext()))); |
| | | data.setRemark(new Content("如有疑问请联系相关物业人员")); |
| | | templateMessage.setData(data); |
| | | templateMessage.setUrl(wechatUrl + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId()); |
| | | templateMessage.setUrl(wechatUrl + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId()+"&communityId="+noticeDto.getCommunityId()); |
| | | logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage)); |
| | | responseEntity = outRestTemplate.postForEntity(sendMsgUrl + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | responseEntity = outRestTemplate.postForEntity(sendTemplate + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | logger.info("微信模板返回内容:{}", responseEntity); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("发送失败", e); |
| | | } finally { |
| | | doSaveLog(startTime, DateUtil.getCurrentDate(), "/pages/notice/detail/detail", JSON.toJSONString(templateMessage), responseEntity, appUserDto.getOpenId()); |
| | |
| | | } |
| | | |
| | | private void doSendToOpenId(NoticeDto noticeDto, String templateId, String accessToken, String nextOpenid, SmallWeChatDto weChatDto) { |
| | | String url = getUser.replace("ACCESS_TOKEN", accessToken); |
| | | String url = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN,WechatConstant.GET_USER_URL); |
| | | if(StringUtil.isEmpty(url)){ |
| | | url = getUser; |
| | | } |
| | | url = url.replace("ACCESS_TOKEN", accessToken); |
| | | if (!StringUtil.isEmpty(nextOpenid)) { |
| | | url += ("&next_openid=" + nextOpenid); |
| | | } |
| | |
| | | miniprogram = new Miniprogram(); |
| | | miniprogram.setAppid(wechatUrl); |
| | | } |
| | | |
| | | String sendTemplate = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN,WechatConstant.SEND_TEMPLATE_URL); |
| | | if(StringUtil.isEmpty(sendTemplate)){ |
| | | sendTemplate = sendMsgUrl; |
| | | } |
| | | ResponseEntity<String> responseEntity = null; |
| | | for (int openIndex = 0; openIndex < openids.size(); openIndex++) { |
| | | Date startTime = DateUtil.getCurrentDate(); |
| | |
| | | templateMessage.setData(data); |
| | | if (!StringUtil.isEmpty(wechatUrl)) { |
| | | if (miniprogram == null) { |
| | | templateMessage.setUrl(wechatUrl + "/#/pages/notice/detail/detail?noticeId=" + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId()); |
| | | templateMessage.setUrl(wechatUrl + "/#/pages/notice/detail/detail?noticeId=" + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId()+"&communityId="+noticeDto.getCommunityId()); |
| | | } else { |
| | | miniprogram.setPagepath("/pages/notice/detail/detail?noticeId=" + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId()); |
| | | miniprogram.setPagepath("/pages/notice/detail/detail?noticeId=" + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId()+"&communityId="+noticeDto.getCommunityId()); |
| | | templateMessage.setMiniprogram(miniprogram); |
| | | } |
| | | } |
| | | logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage)); |
| | | responseEntity = outRestTemplate.postForEntity(sendMsgUrl + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | responseEntity = outRestTemplate.postForEntity(sendTemplate + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | logger.info("微信模板返回内容:{}", responseEntity); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("发送失败", e); |
| | | } finally { |
| | | doSaveLog(startTime, DateUtil.getCurrentDate(), "/pages/notice/detail/detail", JSON.toJSONString(templateMessage), responseEntity, openId); |