Browse Source

Merge branch 'dev_wx_msg' into dev_temp

# Conflicts:
#	epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectProcessServiceImpl.java
dev_shibei_match
sunyuchao 5 years ago
parent
commit
6e85cc9faa
  1. 16
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/WxmpResiUserSubscribeDao.java
  2. 17
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/WxmpWorkUserSubscribeDao.java
  3. 123
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/WxmpMessageServiceImpl.java
  4. 15
      epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/WxmpResiUserSubscribeDao.xml
  5. 15
      epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/WxmpWorkUserSubscribeDao.xml
  6. 1
      epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectProcessServiceImpl.java
  7. 19
      epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java

16
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/WxmpResiUserSubscribeDao.java

@ -36,11 +36,12 @@ public interface WxmpResiUserSubscribeDao extends BaseDao<WxmpResiUserSubscribeE
* @param openId
* @param templateId
* @param customerId
* @param userId
* @return java.lang.Integer
* @Author liushaowen
* @Date 2020/10/22 9:30
*/
Integer getResiSubscribeInfo(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId);
Integer getResiSubscribeInfo(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId,@Param("userId") String userId);
/**
* @Description 减少订阅条数
@ -52,7 +53,7 @@ public interface WxmpResiUserSubscribeDao extends BaseDao<WxmpResiUserSubscribeE
* @Author liushaowen
* @Date 2020/10/22 9:38
*/
int decreaseResiSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId,@Param("num") int i);
int decreaseResiSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId,@Param("num") int i,@Param("userId") String userId);
/**
* @Description 清空订阅条数修改订阅状态
@ -63,16 +64,7 @@ public interface WxmpResiUserSubscribeDao extends BaseDao<WxmpResiUserSubscribeE
* @Author liushaowen
* @Date 2020/10/22 13:23
*/
int clearResiSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId);
/**
* @Description 获取模板id
* @param openId
* @param customerId
* @return java.lang.Integer
* @Author liushaowen
* @Date 2020/10/23 10:53
*/
String getResiSubscribeTemplateId(@Param("openId") String openId, @Param("customerId") String customerId);
int clearResiSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId,@Param("userId") String userId);
WxmpResiUserSubscribeEntity getWxResiSubscribe(@Param("userId") String userId, @Param("customerId") String customerId,
@Param("templateId") String templateId);

17
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/WxmpWorkUserSubscribeDao.java

@ -36,11 +36,12 @@ public interface WxmpWorkUserSubscribeDao extends BaseDao<WxmpWorkUserSubscribeE
* @param openId
* @param templateId
* @param customerId
* @param userId
* @return java.lang.Integer
* @Author liushaowen
* @Date 2020/10/22 9:31
*/
Integer getWorkSubscribeInfo(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId);
Integer getWorkSubscribeInfo(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId,@Param("userId") String userId);
/**
* @Description 减少订阅条数
@ -52,7 +53,7 @@ public interface WxmpWorkUserSubscribeDao extends BaseDao<WxmpWorkUserSubscribeE
* @Author liushaowen
* @Date 2020/10/22 9:38
*/
int decreaseWorkSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId, @Param("num") int i);
int decreaseWorkSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId, @Param("num") int i,@Param("userId") String userId);
/**
* @Description 清空订阅数修改订阅状态
@ -63,17 +64,7 @@ public interface WxmpWorkUserSubscribeDao extends BaseDao<WxmpWorkUserSubscribeE
* @Author liushaowen
* @Date 2020/10/22 13:22
*/
int clearWorkSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId);
/**
* @Description 获取模板id
* @param openId
* @param customerId
* @return java.lang.String
* @Author liushaowen
* @Date 2020/10/23 10:54
*/
String getWorkSubscribeTemplateId(@Param("openId") String openId, @Param("customerId") String customerId);
int clearWorkSubscribeCount(@Param("openId") String openId, @Param("templateId") String templateId, @Param("customerId") String customerId,@Param("userId") String userId);
WxmpWorkUserSubscribeEntity getWxWorkSubscribe(@Param("userId") String userId,
@Param("customerId") String customerId,

123
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/WxmpMessageServiceImpl.java

@ -32,6 +32,7 @@ import com.epmet.dao.WxmpResiUserSubscribeDao;
import com.epmet.dao.WxmpTemplateMsgSubscribeStatusDao;
import com.epmet.dao.WxmpUserSubscribeRecordDao;
import com.epmet.dao.WxmpWorkUserSubscribeDao;
import com.epmet.dto.UserWechatDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.entity.*;
@ -120,7 +121,17 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
@Override
public void sendWxSubscribeMessage(List<WxSubscribeMessageFormDTO> msgList) {
logger.info("待发送订阅消息数量:{}", msgList.size());
if (!(msgList.size() > NumConstant.ZERO)) {
throw new RenException("待发送消息不能为空");
}
int succecssCount = 0;
// 获取templateId
CustomerTemplateListFormDTO customerTemplateListFormDTO = new CustomerTemplateListFormDTO();
customerTemplateListFormDTO.setCustomerId(msgList.get(0).getCustomerId());
customerTemplateListFormDTO.setPublicId(WxmpMessageConstant.TEMPLATE_TYPE);
List<CustomerTemplateListResultDTO> customerTemplateListResultDTOS = customerTemplateList(customerTemplateListFormDTO);
// 获取AccessToken
Map<String,String> accessTokenMap = getAccessToken(msgList.get(0).getCustomerId());
for (WxSubscribeMessageFormDTO msg : msgList) {
try {
String userId = msg.getUserId();
@ -142,46 +153,16 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
throw new WxSubscribeException("clientType有误", "", openId);
}
} catch (Exception e) {
throw new WxSubscribeException("连接User服务失败", "", "");
throw new WxSubscribeException("连接User服务失败" + e.getMessage(), "", "");
}
if (StringUtils.isBlank(openId)) {
throw new WxSubscribeException("openId获取失败", "", "");
}
//获取accessToken
String clientTypeRedis = null;
if (WxmpMessageConstant.RESI.equals(msg.getClientType())) {
clientTypeRedis = WxmpMessageConstant.RESI;
}
if (WxmpMessageConstant.GOV_DB.equals(msg.getClientType())) {
clientTypeRedis = WxmpMessageConstant.GOV_REDIS;
}
StringBuilder key = new StringBuilder(msg.getCustomerId()).append(":").append(clientTypeRedis);
Map<String, Object> authorizerRefreshToken = new HashMap<>();
try {
authorizerRefreshToken = wxmpMessageRedis.getAuthorizerRefreshToken(key.toString());
} catch (Exception e) {
throw new WxSubscribeException("连接缓存服务器失败", "", openId);
}
String accessToken = (String) authorizerRefreshToken.get(WxmpMessageConstant.AUTHORIZER_ACCESS_TOKEN);
if (StringUtils.isBlank(accessToken)) {
throw new WxSubscribeException("accessToken获取失败", "", openId);
}
//获取模板id
// if (WxmpMessageConstant.RESI.equals(clientType)) {
// templateId = wxmpResiUserSubscribeDao.getResiSubscribeTemplateId(openId, customerId);
// } else if (WxmpMessageConstant.GOV_DB.equals(clientType)) {
// templateId = wxmpWorkUserSubscribeDao.getWorkSubscribeTemplateId(openId, customerId);
// }
CustomerTemplateListFormDTO customerTemplateListFormDTO = new CustomerTemplateListFormDTO();
customerTemplateListFormDTO.setCustomerId(customerId);
customerTemplateListFormDTO.setPublicId(WxmpMessageConstant.TEMPLATE_TYPE);
List<CustomerTemplateListResultDTO> customerTemplateListResultDTOS = customerTemplateList(customerTemplateListFormDTO);
if (customerTemplateListResultDTOS.size() > NumConstant.ZERO) {
for (CustomerTemplateListResultDTO customerTemplateListResultDTO : customerTemplateListResultDTOS) {
if (WxmpMessageConstant.GOV_REDIS.equals(customerTemplateListResultDTO.getClientType())){
if (WxmpMessageConstant.GOV_REDIS.equals(customerTemplateListResultDTO.getClientType())) {
customerTemplateListResultDTO.setClientType(WxmpMessageConstant.GOV_DB);
}
if (clientType.equals(customerTemplateListResultDTO.getClientType())) {
@ -197,9 +178,9 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
//判断用户是否有次数
Integer count = null;
if (WxmpMessageConstant.RESI.equals(clientType)) {
count = wxmpResiUserSubscribeDao.getResiSubscribeInfo(openId, templateId, customerId);
count = wxmpResiUserSubscribeDao.getResiSubscribeInfo(openId, templateId, customerId, userId);
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) {
count = wxmpWorkUserSubscribeDao.getWorkSubscribeInfo(openId, templateId, customerId);
count = wxmpWorkUserSubscribeDao.getWorkSubscribeInfo(openId, templateId, customerId, userId);
}
if (count == null) {
//用户未订阅
@ -209,6 +190,17 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
throw new WxSubscribeException("用户可用额度不足", templateId, openId);
}
//获取accessToken
String accessToken = null;
if (WxmpMessageConstant.RESI.equals(clientType)) {
accessToken = accessTokenMap.get("resiToken");
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) {
accessToken = accessTokenMap.get("govToken");
}
if (StringUtils.isBlank(accessToken)) {
throw new WxSubscribeException("accessToken获取失败"+accessTokenMap.get("errorMsg"), "", openId);
}
//发送消息
JSONObject jsonObject = new JSONObject();
JSONObject data = new JSONObject();
@ -259,9 +251,9 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
//订阅条数-1
int decrease = 0;
if (WxmpMessageConstant.RESI.equals(clientType)) {
decrease = wxmpResiUserSubscribeDao.decreaseResiSubscribeCount(openId, templateId, customerId, 1);
decrease = wxmpResiUserSubscribeDao.decreaseResiSubscribeCount(openId, templateId, customerId, 1,userId);
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) {
decrease = wxmpWorkUserSubscribeDao.decreaseWorkSubscribeCount(openId, templateId, customerId, 1);
decrease = wxmpWorkUserSubscribeDao.decreaseWorkSubscribeCount(openId, templateId, customerId, 1,userId);
}
if (decrease == 0) {
logger.error("消息{}发送成功但订阅条数-1失败", JSON.toJSONString(msg));
@ -277,9 +269,9 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
if (errcode.equals(WxmpMessageConstant.USER_REFUSED)) {
int clear = 0;
if (WxmpMessageConstant.RESI.equals(clientType)) {
clear = wxmpResiUserSubscribeDao.clearResiSubscribeCount(openId, templateId, customerId);
clear = wxmpResiUserSubscribeDao.clearResiSubscribeCount(openId, templateId, customerId,userId);
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) {
clear = wxmpWorkUserSubscribeDao.clearWorkSubscribeCount(openId, templateId, customerId);
clear = wxmpWorkUserSubscribeDao.clearWorkSubscribeCount(openId, templateId, customerId,userId);
}
if (clear == 0) {
logger.error("消息{}发送失败且清空订阅条数失败", JSON.toJSONString(msg));
@ -319,7 +311,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
wxmpMsgSendRecordEntity.setCustomerId(msg.getCustomerId());
wxmpMsgSendRecordEntity.setClientType(msg.getClientType());
wxmpMsgSendRecordEntity.setTemplateId(templateId);
wxmpMsgSendRecordEntity.setGridId(msg.getGridId()==null?"":msg.getGridId());
wxmpMsgSendRecordEntity.setGridId(msg.getGridId() == null ? "" : msg.getGridId());
wxmpMsgSendRecordEntity.setUserId(msg.getUserId());
wxmpMsgSendRecordEntity.setWxOpenId(openId);
wxmpMsgSendRecordEntity.setBehaviorType(msg.getBehaviorType());
@ -330,6 +322,57 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
return wxmpMsgSendRecordEntity;
}
//获取AccessToken
private Map<String,String> getAccessToken(String customerId) {
EnvEnum envEnum = EnvEnum.getCurrentEnv();
String resiAccessToken = null;
String govAccessToken = null;
String errorMsg = null;
if (EnvEnum.PROD.getCode().equals(envEnum.getCode())) {
//居民端
StringBuilder resiKey = new StringBuilder(customerId).append(":").append(WxmpMessageConstant.RESI);
Map<String, Object> authorizerRefreshToken = new HashMap<>();
try {
authorizerRefreshToken = wxmpMessageRedis.getAuthorizerRefreshToken(resiKey.toString());
} catch (Exception e) {
errorMsg = e.getMessage();
}
resiAccessToken = (String) authorizerRefreshToken.get(WxmpMessageConstant.AUTHORIZER_ACCESS_TOKEN);
//政府端
StringBuilder govKey = new StringBuilder(customerId).append(":").append(WxmpMessageConstant.GOV_REDIS);
authorizerRefreshToken = new HashMap<>();
try {
authorizerRefreshToken = wxmpMessageRedis.getAuthorizerRefreshToken(resiKey.toString());
} catch (Exception e) {
errorMsg = e.getMessage();
}
govAccessToken = (String) authorizerRefreshToken.get(WxmpMessageConstant.AUTHORIZER_ACCESS_TOKEN);
} else {
String url = "https://epmet-cloud.elinkservice.cn/api/third/pacustomer/tokenlist";
JSONObject postData = new JSONObject();
postData.put("customerId", customerId);
String data = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(postData)).getData();
JSONObject toResult = JSON.parseObject(data);
Result mapToResult = ConvertUtils.mapToEntity(toResult, Result.class);
if (null != toResult.get("code")) {
mapToResult.setCode(((Integer) toResult.get("code")).intValue());
}
if (!mapToResult.success()) {
errorMsg = StringUtils.isBlank(mapToResult.getMsg()) ? mapToResult.getInternalMsg() : mapToResult.getMsg();
}
Object CustomerTokensResultDTO = mapToResult.getData();
JSONObject json = JSON.parseObject(CustomerTokensResultDTO.toString());
CustomerTokensResultDTO customerTokensResultDTO = ConvertUtils.mapToEntity(json, CustomerTokensResultDTO.class);
resiAccessToken = customerTokensResultDTO.getResiAuthorizerToken();
govAccessToken = customerTokensResultDTO.getWorkAuthorizerToken();
}
Map resultMap = new HashMap();
resultMap.put("resiToken",resiAccessToken);
resultMap.put("govToken",govAccessToken);
resultMap.put("errorMsg",errorMsg);
return resultMap;
}
/**
* @return
* @Description 居民端工作端-获取客户小程序模板列表
@ -385,7 +428,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService {
List<Object> resultList = (List<Object>) mapToResult.getData();
List<CustomerTemplateListResultDTO> list = new ArrayList<>();
//必须转换
for(Object f:resultList){
for (Object f : resultList) {
JSONObject json = JSON.parseObject(f.toString());
CustomerTemplateListResultDTO ff = ConvertUtils.mapToEntity(json, CustomerTemplateListResultDTO.class);
list.add(ff);

15
epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/WxmpResiUserSubscribeDao.xml

@ -12,6 +12,7 @@
and customer_id = #{customerId}
and template_id = #{templateId}
and wx_open_id = #{openId}
and user_id = #{userId}
and wx_subscribe_status = 'subscribe'
</select>
@ -23,6 +24,7 @@
and customer_id = #{customerId}
and template_id = #{templateId}
and wx_open_id = #{openId}
and user_id = #{userId}
and wx_subscribe_status = 'subscribe'
</update>
@ -35,20 +37,9 @@
and customer_id = #{customerId}
and template_id = #{templateId}
and wx_open_id = #{openId}
and user_id = #{userId}
</update>
<select id="getResiSubscribeTemplateId" resultType="String">
select
template_id
from Wxmp_Resi_User_Subscribe
where
del_flag = 0
and customer_id = #{customerId}
and wx_open_id = #{openId}
and wx_subscribe_status = 'subscribe'
limit 1
</select>
<!--增加订阅次数-->
<update id="incrSubscribeCount">
update wxmp_resi_user_subscribe

15
epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/WxmpWorkUserSubscribeDao.xml

@ -18,8 +18,10 @@
from Wxmp_Work_User_Subscribe
where
del_flag =0
and customer_id = #{customerId}
and template_id = #{templateId}
and wx_open_id = #{openId}
and user_id = #{userId}
and wx_subscribe_status = 'subscribe'
</select>
@ -31,6 +33,7 @@
and customer_id = #{customerId}
and template_id = #{templateId}
and wx_open_id = #{openId}
and user_id = #{userId}
and wx_subscribe_status = 'subscribe'
</update>
<update id="clearWorkSubscribeCount" parameterType="String">
@ -42,18 +45,8 @@
and customer_id = #{customerId}
and template_id = #{templateId}
and wx_open_id = #{openId}
and user_id = #{userId}
</update>
<select id="getWorkSubscribeTemplateId" resultType="String">
select
template_id
from Wxmp_Work_User_Subscribe
where
del_flag = 0
and customer_id = #{customerId}
and wx_open_id = #{openId}
and wx_subscribe_status = 'subscribe'
limit 1
</select>
<update id="unSubscribe">
update wxmp_work_user_subscribe

1
epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectProcessServiceImpl.java

@ -52,6 +52,7 @@ import com.epmet.entity.ProjectProcessEntity;
import com.epmet.entity.ProjectStaffEntity;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.EpmetUserFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgFeignClient;

19
epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java

@ -849,6 +849,7 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
**/
@Override
public List<LatestListResultDTO> getClosedProjectList(LatestListFormDTO formDTO) {
return baseDao.selectClosedProjectList(formDTO);
}
@ -1231,6 +1232,8 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
}));
//通知
List<UserMessageFormDTO> msgList = new ArrayList<>();
//10.29 项目滞留提醒添加推送微信消息 sun
List<WxSubscribeMessageFormDTO> wxmpMsgList = new ArrayList<>();
list.forEach(dto -> {
String title;
String msg;
@ -1269,8 +1272,24 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
messageFormDTO.setMessageContent(msg);
messageFormDTO.setReadFlag(Constant.UNREAD);
msgList.add(messageFormDTO);
//10.29 项目滞留提醒添加推送微信消息 sun
WxSubscribeMessageFormDTO wxmp = new WxSubscribeMessageFormDTO();
wxmp.setCustomerId(customerId);
wxmp.setClientType(ProjectConstant.GOV);
wxmp.setUserId(dto.getStaffId());
wxmp.setBehaviorType("项目滞留提醒");
wxmp.setMessageContent(msg);
wxmp.setMessageTime(new Date());
wxmp.setGridId(StrConstant.STAR);
wxmpMsgList.add(wxmp);
});
messageFeignClient.saveUserMessageList(msgList);
logger.info("项目滞留提醒,开始推送微信订阅消息");
Result result = epmetMessageOpenFeignClient.sendWxSubscribeMessage(wxmpMsgList);
if (!result.success()) {
logger.error("项目滞留提醒,发送微信订阅消息失败" + JSON.toJSONString(result));
}
}

Loading…
Cancel
Save