From 22d7512ecb341426ecaa5ac8d48d7aa2b37c1059 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 09 六月 2022 16:27:41 +0800
Subject: [PATCH] 优化代码
---
service-job/src/main/java/com/java110/job/task/wechat/WeChatPushMessageTemplate.java | 349 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 307 insertions(+), 42 deletions(-)
diff --git a/service-job/src/main/java/com/java110/job/task/wechat/WeChatPushMessageTemplate.java b/service-job/src/main/java/com/java110/job/task/wechat/WeChatPushMessageTemplate.java
old mode 100644
new mode 100755
index e5d6c51..b93f05c
--- a/service-job/src/main/java/com/java110/job/task/wechat/WeChatPushMessageTemplate.java
+++ b/service-job/src/main/java/com/java110/job/task/wechat/WeChatPushMessageTemplate.java
@@ -1,17 +1,28 @@
package com.java110.job.task.wechat;
import com.alibaba.fastjson.JSON;
+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.Java110ThreadPoolFactory;
import com.java110.core.factory.WechatFactory;
+import com.java110.core.log.LoggerFactory;
+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.dto.smallWeChat.SmallWeChatDto;
import com.java110.dto.smallWechatAttr.SmallWechatAttrDto;
import com.java110.dto.task.TaskDto;
+import com.java110.dto.wechatSubscribe.WechatSubscribeDto;
import com.java110.entity.wechat.Content;
import com.java110.entity.wechat.Data;
+import com.java110.entity.wechat.Miniprogram;
import com.java110.entity.wechat.PropertyFeeTemplateMessage;
import com.java110.intf.community.INoticeInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
@@ -19,15 +30,26 @@
import com.java110.intf.store.ISmallWechatAttrInnerServiceSMO;
import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO;
+import com.java110.intf.user.IWechatSubscribeV1InnerServiceSMO;
import com.java110.job.quartz.TaskSystemQuartz;
+import com.java110.po.logSystemError.LogSystemErrorPo;
+import com.java110.po.transactionLog.TransactionLogPo;
+import com.java110.po.wechatSubscribe.WechatSubscribePo;
+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;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
/**
@@ -40,6 +62,11 @@
public class WeChatPushMessageTemplate extends TaskSystemQuartz {
private static Logger logger = LoggerFactory.getLogger(WeChatPushMessageTemplate.class);
+
+ public static final int DEFAULT_THREAD_NUM = 20;
+ public static final int DEFAULT_SUBSCRIBE_PERSON = 100;
+
+ public static final int DEFAULT_QUERY_APP_OWNER_COUNT = 50;
@Autowired
private INoticeInnerServiceSMO noticeInnerServiceSMOImpl;
@@ -58,17 +85,31 @@
@Autowired
private IOwnerRoomRelInnerServiceSMO ownerRoomRelInnerServiceSMOImpl;
+ @Autowired
+ private ISaveTransactionLogSMO saveTransactionLogSMOImpl;
@Autowired
private RestTemplate outRestTemplate;
+ @Autowired
+ private ISaveSystemErrorSMO saveSystemErrorSMOImpl;
+
+ @Autowired
+ private IWechatSubscribeV1InnerServiceSMO wechatSubscribeV1InnerServiceSMOImpl;
+
//妯℃澘淇℃伅鎺ㄩ�佸湴鍧�
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";
+
+ private Java110ThreadPoolFactory<PublicWeChatPushMessageTemplate> publicWeChatPushMessageTemplateJava110ThreadPoolFactory = null;
@Override
protected void process(TaskDto taskDto) {
logger.debug("寮�濮嬫墽琛屽井淇℃ā鏉夸俊鎭帹閫�" + taskDto.toString());
+
+ //鍒涘缓杩炴帴姹�
+ publicWeChatPushMessageTemplateJava110ThreadPoolFactory = Java110ThreadPoolFactory.getInstance().createThreadPool(DEFAULT_THREAD_NUM);
// 鑾峰彇灏忓尯
List<CommunityDto> communityDtos = getAllCommunity();
@@ -77,9 +118,16 @@
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);
}
}
+
+ publicWeChatPushMessageTemplateJava110ThreadPoolFactory.stop();
}
private void publishMsg(TaskDto taskDto, CommunityDto communityDto) throws Exception {
@@ -119,46 +167,105 @@
}
//
- NoticeDto noticeDto = new NoticeDto();
- noticeDto.setCommunityId(communityDto.getCommunityId());
- noticeDto.setPage(1);
- noticeDto.setRow(50);
- noticeDto.setState(NoticeDto.STATE_WAIT);
- noticeDto.setNoticeTypeCd(NoticeDto.NOTICE_TYPE_OWNER_WECHAT);
- List<NoticeDto> noticeDtos = noticeInnerServiceSMOImpl.queryNotices(noticeDto);
+ List<NoticeDto> noticeDtos = getNotices(communityDto.getCommunityId());
if (noticeDtos == null || noticeDtos.size() < 1) {
return;
}
for (NoticeDto tmpNotice : noticeDtos) {
- doSentWechat(tmpNotice, templateId, accessToken);
+ 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) {
+ @Java110Synchronized(value = "communityId")
+ private List<NoticeDto> getNotices(String communityId) {
+ NoticeDto noticeDto = new NoticeDto();
+ noticeDto.setCommunityId(communityId);
+ noticeDto.setPage(1);
+ noticeDto.setRow(50);
+ noticeDto.setState(NoticeDto.STATE_WAIT);
+ noticeDto.setNoticeTypeCd(NoticeDto.NOTICE_TYPE_OWNER_WECHAT);
+ List<NoticeDto> noticeDtos = noticeInnerServiceSMOImpl.queryNotices(noticeDto);
+
+ //鏇存柊涓哄彂閫佷腑
+ for (NoticeDto noticeDto1 : noticeDtos) {
+ noticeDto = new NoticeDto();
+ noticeDto.setNoticeId(noticeDto1.getNoticeId());
+ noticeDto.setState(NoticeDto.STATE_DOING);
+ noticeDto.setCommunityId(communityId);
+ noticeInnerServiceSMOImpl.updateNotice(noticeDto);
+ }
+
+ return noticeDtos;
+ }
+
+ 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;
+// }
+
String objType = noticeDto.getObjType();
switch (objType) {
- case NoticeDto.OBJ_TYPE_COMMUNITY:
- sendAllOwner(noticeDto, templateId, accessToken);
+ case NoticeDto.OBJ_TYPE_ALL:
+ sendAllOwner(noticeDto, templateId, accessToken, weChatDto);
break;
case NoticeDto.OBJ_TYPE_FLOOR:
- sendFloorOwner(noticeDto, templateId, accessToken);
+ sendFloorOwner(noticeDto, templateId, accessToken, weChatDto);
break;
case NoticeDto.OBJ_TYPE_UNIT:
- sendUnitOwner(noticeDto, templateId, accessToken);
+ sendUnitOwner(noticeDto, templateId, accessToken, weChatDto);
break;
case NoticeDto.OBJ_TYPE_ROOM:
- sendRoomOwner(noticeDto, templateId, accessToken);
+ sendRoomOwner(noticeDto, templateId, accessToken, weChatDto);
+ break;
+ case NoticeDto.OBJ_TYPE_COMMUNITY:
+ sendCommunityOwner(noticeDto, templateId, accessToken, weChatDto);
break;
}
+ NoticeDto tmpNoticeDto = new NoticeDto();
+ tmpNoticeDto.setNoticeId(noticeDto.getNoticeId());
+ tmpNoticeDto.setState(NoticeDto.STATE_FINISH);
+ noticeInnerServiceSMOImpl.updateNotice(tmpNoticeDto);
+
}
- private void sendFloorOwner(NoticeDto noticeDto, String templateId, String accessToken) {
+ 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());
+ int count = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsersCount(ownerAppUserDto);
+
+ double maxPage = Math.ceil(count/DEFAULT_QUERY_APP_OWNER_COUNT)+1;
+
+ for(int page = 0; page < maxPage; page++){
+ ownerAppUserDto.setPage(page+1);
+ ownerAppUserDto.setRow(DEFAULT_QUERY_APP_OWNER_COUNT);
+ List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+ doSend(ownerAppUserDtos, noticeDto, templateId, accessToken, weChatDto);
+ }
+//
+// List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+// doSend(ownerAppUserDtos, noticeDto, templateId, accessToken, weChatDto);
+ }
+
+ private void sendFloorOwner(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) {
RoomDto roomDto = new RoomDto();
roomDto.setCommunityId(noticeDto.getCommunityId());
@@ -180,11 +287,11 @@
ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
ownerAppUserDto.setMemberId(ownerRoomRelDtos.get(0).getOwnerId());
List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
- doSend(ownerAppUserDtos, noticeDto, templateId, accessToken);
+ doSend(ownerAppUserDtos, noticeDto, templateId, accessToken, weChatDto);
}
}
- private void sendUnitOwner(NoticeDto noticeDto, String templateId, String accessToken) {
+ private void sendUnitOwner(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) {
RoomDto roomDto = new RoomDto();
roomDto.setCommunityId(noticeDto.getCommunityId());
@@ -206,11 +313,11 @@
ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
ownerAppUserDto.setMemberId(ownerRoomRelDtos.get(0).getOwnerId());
List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
- doSend(ownerAppUserDtos, noticeDto, templateId, accessToken);
+ doSend(ownerAppUserDtos, noticeDto, templateId, accessToken, weChatDto);
}
}
- private void sendRoomOwner(NoticeDto noticeDto, String templateId, String accessToken) {
+ private void sendRoomOwner(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) {
RoomDto roomDto = new RoomDto();
roomDto.setCommunityId(noticeDto.getCommunityId());
@@ -232,34 +339,192 @@
ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
ownerAppUserDto.setMemberId(ownerRoomRelDtos.get(0).getOwnerId());
List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
- doSend(ownerAppUserDtos, noticeDto, templateId, accessToken);
+ doSend(ownerAppUserDtos, noticeDto, templateId, accessToken, weChatDto);
}
}
- private void sendAllOwner(NoticeDto noticeDto, String templateId, String accessToken) {
- OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
- ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
- List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
- doSend(ownerAppUserDtos, noticeDto, templateId, accessToken);
- }
+ private void sendAllOwner(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) {
+ //鍒ゆ柇鍏虫敞琛ㄧ殑鐢ㄦ埛閲� 鏄惁澶т簬100浜�
+ WechatSubscribeDto wechatSubscribeDto = new WechatSubscribeDto();
+ wechatSubscribeDto.setAppId(weChatDto.getAppId());
+ wechatSubscribeDto.setOpenType(WechatSubscribeDto.OPEN_TYPE_WECHAT);
- private void doSend(List<OwnerAppUserDto> ownerAppUserDtos, NoticeDto noticeDto, String templateId, String accessToken) {
- String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL") + "/#/pages/notice/detail/detail?noticeId=";
- for (OwnerAppUserDto appUserDto : ownerAppUserDtos) {
+ int count = wechatSubscribeV1InnerServiceSMOImpl.queryWechatSubscribesCount(wechatSubscribeDto);
+
+ //鍙兘鍏紬鍙� 宸茬粡 浣跨敤浜嗗ソ涔� 浣嗘槸 绋嬪簭鍙兘鍒氬紑濮嬬敤
+ if (count < DEFAULT_SUBSCRIBE_PERSON) {
+ //doSendToOpenId(noticeDto, templateId, accessToken, "", weChatDto);
+ WechatSubscribePo tmpWechatSubscribePo = new WechatSubscribePo();
+ tmpWechatSubscribePo.setAppId(weChatDto.getAppId());
+ wechatSubscribeV1InnerServiceSMOImpl.deleteWechatSubscribe(tmpWechatSubscribePo);
+ getAllOpenId(accessToken, "", weChatDto);
+ }
+
+ List<WechatSubscribeDto> wechatSubscribeDtos = wechatSubscribeV1InnerServiceSMOImpl.queryDistinctWechatSubscribes(wechatSubscribeDto);
+
+ if (wechatSubscribeDtos == null || wechatSubscribeDtos.size() < 1) {
+ return;
+ }
+
+ String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL");
+ Miniprogram miniprogram = null;
+ if (wechatUrl.startsWith("https://") || wechatUrl.startsWith("http://")) {
+
+ } else {
+ 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 (WechatSubscribeDto wechatSubscribeDto1 : wechatSubscribeDtos) {
+ Date startTime = DateUtil.getCurrentDate();
Data data = new Data();
PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
- templateMessage.setTemplate_id(templateId);
- templateMessage.setTouser(appUserDto.getOpenId());
- data.setFirst(new Content(noticeDto.getTitle()));
- data.setKeyword1(new Content(noticeDto.getTitle()));
- data.setKeyword2(new Content(noticeDto.getStartTime()));
- data.setKeyword3(new Content(noticeDto.getContext()));
- data.setRemark(new Content("濡傛湁鐤戦棶璇疯仈绯荤浉鍏崇墿涓氫汉鍛�"));
- templateMessage.setData(data);
- templateMessage.setUrl(wechatUrl + noticeDto.getNoticeId());
- logger.info("鍙戦�佹ā鏉挎秷鎭唴瀹�:{}", JSON.toJSONString(templateMessage));
- ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(sendMsgUrl + accessToken, JSON.toJSONString(templateMessage), String.class);
- logger.info("寰俊妯℃澘杩斿洖鍐呭:{}", responseEntity);
+ try {
+ templateMessage.setTemplate_id(templateId);
+ templateMessage.setTouser(wechatSubscribeDto1.getOpenId());
+ data.setFirst(new Content(noticeDto.getTitle()));
+ data.setKeyword1(new Content(noticeDto.getTitle()));
+ data.setKeyword2(new Content(noticeDto.getStartTime()));
+ data.setKeyword3(new Content(StringUtil.delHtmlTag(noticeDto.getContext())));
+ data.setRemark(new Content("濡傛湁鐤戦棶璇疯仈绯荤浉鍏崇墿涓氫汉鍛�"));
+ templateMessage.setData(data);
+ if (!StringUtil.isEmpty(wechatUrl)) {
+ if (miniprogram == null) {
+ 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() + "&communityId=" + noticeDto.getCommunityId());
+ templateMessage.setMiniprogram(miniprogram);
+ }
+ }
+ //骞跺彂澶勭悊
+ PushWechatTemplateMessageThread pushWechatTemplateMessageThread = new PushWechatTemplateMessageThread(outRestTemplate, sendTemplate + accessToken, JSON.toJSONString(templateMessage));
+ publicWeChatPushMessageTemplateJava110ThreadPoolFactory.submit(pushWechatTemplateMessageThread);
+ //responseEntity = outRestTemplate.postForEntity(sendTemplate + accessToken, JSON.toJSONString(templateMessage), String.class);
+ } 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, wechatSubscribeDto1.getOpenId());
+ }
+ }
+ }
+
+ private void getAllOpenId(String accessToken, String nextOpenid, SmallWeChatDto weChatDto) {
+ 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);
+ }
+ ResponseEntity<String> paramOut = outRestTemplate.getForEntity(url, String.class);
+
+ logger.info("鑾峰彇鐢ㄦ埛杩斿洖:{}", paramOut);
+
+ if (paramOut.getStatusCode() != HttpStatus.OK) {
+ throw new IllegalArgumentException(paramOut.getBody());
+ }
+
+ JSONObject paramOutObj = JSONObject.parseObject(paramOut.getBody());
+ if (paramOutObj.containsKey("errcode")) {
+ throw new IllegalArgumentException(paramOut.getBody());
+ }
+
+ if (!paramOutObj.containsKey("data")) {
+ return;
+ }
+ JSONObject dataObj = paramOutObj.getJSONObject("data");
+ JSONArray openids = dataObj.getJSONArray("openid");
+ nextOpenid = paramOutObj.getString("next_openid");
+ List<WechatSubscribePo> wechatSubscribePos = new ArrayList<>();
+ for (int openIndex = 0; openIndex < openids.size(); openIndex++) {
+ String openId = openids.getString(openIndex);
+ WechatSubscribePo wechatSubscribePo = new WechatSubscribePo();
+ wechatSubscribePo.setAppId(weChatDto.getAppId());
+ wechatSubscribePo.setOpenId(openId);
+ wechatSubscribePo.setSubId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_file_id));
+ wechatSubscribePo.setOpenType(WechatSubscribeDto.OPEN_TYPE_WECHAT);
+ wechatSubscribePos.add(wechatSubscribePo);
+ }
+
+ if (wechatSubscribePos.size() > 0) {
+ wechatSubscribeV1InnerServiceSMOImpl.saveWechatSubscribes(wechatSubscribePos);
+ }
+
+ //锛堝叧娉ㄨ�呭垪琛ㄥ凡杩斿洖瀹屾椂锛岃繑鍥瀗ext_openid涓虹┖锛�
+ if (!StringUtil.isEmpty(nextOpenid)) {
+ getAllOpenId(accessToken, nextOpenid, 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();
+ try {
+ Data data = new Data();
+ templateMessage.setTemplate_id(templateId);
+ templateMessage.setTouser(appUserDto.getOpenId());
+ data.setFirst(new Content(noticeDto.getTitle()));
+ data.setKeyword1(new Content(noticeDto.getTitle()));
+ data.setKeyword2(new Content(noticeDto.getStartTime()));
+ data.setKeyword3(new Content(StringUtil.delHtmlTag(noticeDto.getContext())));
+ data.setRemark(new Content("濡傛湁鐤戦棶璇疯仈绯荤浉鍏崇墿涓氫汉鍛�"));
+ templateMessage.setData(data);
+ templateMessage.setUrl(wechatUrl + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId() + "&communityId=" + noticeDto.getCommunityId());
+ logger.info("鍙戦�佹ā鏉挎秷鎭唴瀹�:{}", JSON.toJSONString(templateMessage));
+ //responseEntity = outRestTemplate.postForEntity(sendTemplate + accessToken, JSON.toJSONString(templateMessage), String.class);
+ PushWechatTemplateMessageThread pushWechatTemplateMessageThread = new PushWechatTemplateMessageThread(outRestTemplate, sendTemplate + accessToken, JSON.toJSONString(templateMessage));
+ publicWeChatPushMessageTemplateJava110ThreadPoolFactory.submit(pushWechatTemplateMessageThread);
+ 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 doSaveLog(Date startDate, Date endDate, String serviceCode, String reqJson, ResponseEntity<String> responseEntity, String userId) {
+ try {
+ TransactionLogPo transactionLogPo = new TransactionLogPo();
+ transactionLogPo.setAppId(AppDto.OWNER_WECHAT_PAY);
+ transactionLogPo.setCostTime((endDate.getTime() - startDate.getTime()) + "");
+ transactionLogPo.setIp("");
+ transactionLogPo.setServiceCode(serviceCode);
+ transactionLogPo.setSrcIp("127.0.0.1");
+ transactionLogPo.setState(responseEntity.getStatusCode() != HttpStatus.OK ? "F" : "S");
+ transactionLogPo.setTimestamp(DateUtil.getCurrentDate().getTime() + "");
+ transactionLogPo.setUserId(userId);
+ transactionLogPo.setTransactionId(userId);
+ transactionLogPo.setRequestHeader("");
+ transactionLogPo.setResponseHeader(responseEntity.getHeaders().toSingleValueMap().toString());
+ transactionLogPo.setRequestMessage(reqJson);
+ transactionLogPo.setResponseMessage(responseEntity.getBody());
+ saveTransactionLogSMOImpl.saveLog(transactionLogPo);
+ } catch (Exception e) {
+ logger.error("瀛樻棩蹇楀け璐�", e);
}
}
--
Gitblit v1.8.0