|
|
@ -19,25 +19,28 @@ package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.exception.ValidateException; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.constant.WxMsgTemplateSubscribeStatus; |
|
|
|
import com.epmet.constant.WxmpMessageConstant; |
|
|
|
import com.epmet.dao.WxmpResiUserSubscribeDao; |
|
|
|
import com.epmet.dao.WxmpTemplateMsgSubscribeStatusDao; |
|
|
|
import com.epmet.dao.WxmpUserSubscribeRecordDao; |
|
|
|
import com.epmet.dao.WxmpWorkUserSubscribeDao; |
|
|
|
import com.epmet.dto.form.GetTemplateListFormDTO; |
|
|
|
import com.epmet.dto.form.StaffBasicInfoFormDTO; |
|
|
|
import com.epmet.dto.form.UserBasicInfoFormDTO; |
|
|
|
import com.epmet.dto.form.WxSubscribeMessageFormDTO; |
|
|
|
import com.epmet.dto.result.GetTemplateListResultDTO; |
|
|
|
import com.epmet.entity.WxmpMsgSendRecordEntity; |
|
|
|
import com.epmet.entity.WxmpTemplateMsgSubscribeStatusEntity; |
|
|
|
import com.epmet.dto.result.StaffBasicInfo; |
|
|
|
import com.epmet.dto.result.UserBasicInfo; |
|
|
|
import com.epmet.dto.result.WxMsgAuthInfoResultDTO; |
|
|
|
import com.epmet.entity.*; |
|
|
|
import com.epmet.exception.WxSubscribeException; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.redis.WxmpMessageRedis; |
|
|
@ -50,9 +53,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -85,30 +86,34 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
@Autowired |
|
|
|
private WxmpMsgSendRecordService wxmpMsgSendRecordService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @return void |
|
|
|
* @Description 保存系统授权信息 |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.21 17:29 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void saveSysAuthorizeInfo(String customerId, String clientType, String alwaysVisit, String subscribeStatus, String userId) { |
|
|
|
WxmpTemplateMsgSubscribeStatusEntity userSubscribeStatusEntity = msgSubscribeStatusDao.getUserSubscribeStatusEntity(userId, customerId, clientType); |
|
|
|
if (userSubscribeStatusEntity != null) { |
|
|
|
userSubscribeStatusEntity.setAlwaysVisit(alwaysVisit); |
|
|
|
userSubscribeStatusEntity.setSubscribeStatus(subscribeStatus); |
|
|
|
msgSubscribeStatusDao.updateById(userSubscribeStatusEntity); |
|
|
|
return; |
|
|
|
} |
|
|
|
@Autowired |
|
|
|
private WxmpUserSubscribeRecordDao subscribeRecordDao; |
|
|
|
|
|
|
|
userSubscribeStatusEntity = new WxmpTemplateMsgSubscribeStatusEntity(); |
|
|
|
userSubscribeStatusEntity.setCustomerId(customerId); |
|
|
|
userSubscribeStatusEntity.setClientType(clientType); |
|
|
|
userSubscribeStatusEntity.setAlwaysVisit(alwaysVisit); |
|
|
|
userSubscribeStatusEntity.setSubscribeStatus(subscribeStatus); |
|
|
|
userSubscribeStatusEntity.setUserId(userId); |
|
|
|
msgSubscribeStatusDao.insert(userSubscribeStatusEntity); |
|
|
|
} |
|
|
|
/** |
|
|
|
* @Description 保存系统授权信息 |
|
|
|
* @return void |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.21 17:29 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void saveSysAuthorizeInfo(String customerId, String clientType, String alwaysVisit, String subscribeStatus, String userId, String templateId) { |
|
|
|
WxmpTemplateMsgSubscribeStatusEntity userSubscribeStatusEntity = msgSubscribeStatusDao.getUserSubscribeStatusEntity(userId, customerId, clientType, templateId); |
|
|
|
if (userSubscribeStatusEntity != null) { |
|
|
|
userSubscribeStatusEntity.setAlwaysVisit(alwaysVisit); |
|
|
|
userSubscribeStatusEntity.setSubscribeStatus(subscribeStatus); |
|
|
|
msgSubscribeStatusDao.updateById(userSubscribeStatusEntity); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
userSubscribeStatusEntity = new WxmpTemplateMsgSubscribeStatusEntity(); |
|
|
|
userSubscribeStatusEntity.setCustomerId(customerId); |
|
|
|
userSubscribeStatusEntity.setClientType(clientType); |
|
|
|
userSubscribeStatusEntity.setTemplateId(templateId); |
|
|
|
userSubscribeStatusEntity.setAlwaysVisit(alwaysVisit); |
|
|
|
userSubscribeStatusEntity.setSubscribeStatus(subscribeStatus); |
|
|
|
userSubscribeStatusEntity.setUserId(userId); |
|
|
|
msgSubscribeStatusDao.insert(userSubscribeStatusEntity); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param msgList |
|
|
@ -196,7 +201,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
jsonObject.put(WxmpMessageConstant.TEMPLATE_ID, templateId); |
|
|
|
data.put(WxmpMessageConstant.TITLE, new JSONObject().put("value", ("您有一条" + msg.getBehaviorType()).substring(0, WxmpMessageConstant.TITLE_LIMIT))); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_CONTENT, new JSONObject().put("value", msg.getMessageContent().substring(0, WxmpMessageConstant.MESSAGE_CONTENT_LIMIT))); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_TIME, new JSONObject().put("value", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()))); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_TIME, new JSONObject().put("value", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(msg.getMessageTime()))); |
|
|
|
jsonObject.put(WxmpMessageConstant.DATA, data); |
|
|
|
EnvEnum envEnum = EnvEnum.getCurrentEnv(); |
|
|
|
//选填项
|
|
|
@ -289,7 +294,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
wxmpMsgSendRecordEntity.setBehaviorType(msg.getBehaviorType()); |
|
|
|
wxmpMsgSendRecordEntity.setTitle("您有一条" + msg.getBehaviorType()); |
|
|
|
wxmpMsgSendRecordEntity.setMessageContent(msg.getMessageContent()); |
|
|
|
wxmpMsgSendRecordEntity.setMessageTime(new Date()); |
|
|
|
wxmpMsgSendRecordEntity.setMessageTime(msg.getMessageTime()); |
|
|
|
wxmpMsgSendRecordEntity.setResult(status); |
|
|
|
return wxmpMsgSendRecordEntity; |
|
|
|
} |
|
|
@ -319,4 +324,150 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
public WxMsgAuthInfoResultDTO getAuthorizationInfo(String customerId, String clientType, String loginUserId, String templateId) { |
|
|
|
return msgSubscribeStatusDao.getUserSubscribeStatusDTO(loginUserId, customerId, clientType, templateId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveWxSubscribe(String customerId, String clientType, String templateId, String wxAlwaysVisit, |
|
|
|
String wxSubscribeStatus, String behaviorType, String userId) { |
|
|
|
|
|
|
|
String openId; |
|
|
|
// 1. 用户订阅信息表新增或者更新
|
|
|
|
if (AppClientConstant.APP_GOV.equals(clientType)) { |
|
|
|
// 工作端
|
|
|
|
openId = getWorkOpenId(userId); |
|
|
|
saveWxWorkSubscribe(customerId, templateId, wxSubscribeStatus, userId, openId); |
|
|
|
} else { |
|
|
|
//居民端
|
|
|
|
openId = getResiOpenId(userId); |
|
|
|
saveWxResiSubscribe(customerId, templateId, wxSubscribeStatus, userId, openId); |
|
|
|
} |
|
|
|
|
|
|
|
// 2.保存行为记录
|
|
|
|
WxmpUserSubscribeRecordEntity record = new WxmpUserSubscribeRecordEntity(); |
|
|
|
record.setBehaviorType(behaviorType); |
|
|
|
record.setCustomerId(customerId); |
|
|
|
record.setTemplateId(templateId); |
|
|
|
record.setUserId(userId); |
|
|
|
record.setWxAlwaysVisit(wxAlwaysVisit); |
|
|
|
record.setWxOpenId(openId); |
|
|
|
record.setWxSubscribeStatus(wxSubscribeStatus); |
|
|
|
subscribeRecordDao.insert(record); |
|
|
|
|
|
|
|
// 3.更新用户模板订阅状态
|
|
|
|
WxmpTemplateMsgSubscribeStatusEntity subscribeStatusEntity = msgSubscribeStatusDao.getUserSubscribeStatusEntity(userId, customerId, clientType, templateId); |
|
|
|
if (subscribeStatusEntity == null) { |
|
|
|
subscribeStatusEntity = new WxmpTemplateMsgSubscribeStatusEntity(); |
|
|
|
subscribeStatusEntity.setUserId(userId); |
|
|
|
subscribeStatusEntity.setWxSubscribeStatus(wxSubscribeStatus); |
|
|
|
subscribeStatusEntity.setTemplateId(templateId); |
|
|
|
subscribeStatusEntity.setWxAlwaysVisit(wxAlwaysVisit); |
|
|
|
subscribeStatusEntity.setCustomerId(customerId); |
|
|
|
subscribeStatusEntity.setClientType(clientType); |
|
|
|
msgSubscribeStatusDao.insert(subscribeStatusEntity); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
subscribeStatusEntity.setWxAlwaysVisit(wxAlwaysVisit); |
|
|
|
subscribeStatusEntity.setWxSubscribeStatus(wxSubscribeStatus); |
|
|
|
|
|
|
|
msgSubscribeStatusDao.updateById(subscribeStatusEntity); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 保存居民端微信订阅信息 |
|
|
|
* @return void |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 09:56 |
|
|
|
*/ |
|
|
|
private void saveWxResiSubscribe(String customerId, String templateId, String wxSubscribeStatus, String userId, String openId) { |
|
|
|
|
|
|
|
WxmpResiUserSubscribeEntity wxResiSubscribe = wxmpResiUserSubscribeDao.getWxResiSubscribe(userId, customerId, templateId); |
|
|
|
if (wxResiSubscribe == null) { |
|
|
|
WxmpResiUserSubscribeEntity insert = new WxmpResiUserSubscribeEntity(); |
|
|
|
insert.setCount(WxMsgTemplateSubscribeStatus.SUBSCRIBE.equals(wxSubscribeStatus) ? 1 : 0); |
|
|
|
insert.setCustomerId(customerId); |
|
|
|
insert.setTemplateId(templateId); |
|
|
|
insert.setUserId(userId); |
|
|
|
insert.setWxOpenId(openId); |
|
|
|
insert.setWxSubscribeStatus(wxSubscribeStatus); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (WxMsgTemplateSubscribeStatus.SUBSCRIBE.equals(wxSubscribeStatus)) { |
|
|
|
wxmpResiUserSubscribeDao.incrSubscribeCount(1, userId, customerId, templateId, openId); |
|
|
|
} else { |
|
|
|
wxmpResiUserSubscribeDao.unSubscribe(userId, customerId, templateId, openId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 保存工作端订阅信息 |
|
|
|
* @return void |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 14:21 |
|
|
|
*/ |
|
|
|
private void saveWxWorkSubscribe(String customerId, String templateId, String wxSubscribeStatus, String userId, String openId) { |
|
|
|
WxmpWorkUserSubscribeEntity wxWorkSubscribe = wxmpWorkUserSubscribeDao.getWxWorkSubscribe(userId, customerId, templateId); |
|
|
|
if (wxWorkSubscribe == null) { |
|
|
|
WxmpWorkUserSubscribeEntity insert = new WxmpWorkUserSubscribeEntity(); |
|
|
|
insert.setCount(WxMsgTemplateSubscribeStatus.SUBSCRIBE.equals(wxSubscribeStatus) ? 1 : 0); |
|
|
|
insert.setCustomerId(customerId); |
|
|
|
insert.setTemplateId(templateId); |
|
|
|
insert.setUserId(userId); |
|
|
|
insert.setWxOpenId(openId); |
|
|
|
insert.setWxSubscribeStatus(wxSubscribeStatus); |
|
|
|
wxmpWorkUserSubscribeDao.insert(insert); |
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
if (WxMsgTemplateSubscribeStatus.SUBSCRIBE.equals(wxSubscribeStatus)) { |
|
|
|
wxmpWorkUserSubscribeDao.incrSubscribeCount(1, userId, customerId, templateId, openId); |
|
|
|
} else { |
|
|
|
wxmpWorkUserSubscribeDao.unSubscribe(userId, customerId, templateId, openId); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 根据UserId查询居民OpenId |
|
|
|
* @return string |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 13:35 |
|
|
|
*/ |
|
|
|
public String getResiOpenId(String userId) { |
|
|
|
UserBasicInfoFormDTO bif = new UserBasicInfoFormDTO(); |
|
|
|
bif.setUserId(userId); |
|
|
|
Result<UserBasicInfo> result = epmetUserOpenFeignClient.getUserBasicInfo(bif); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException(String.format("查询居民OpenId失败,userId:%s,错误信息:%s",userId , result.getInternalMsg())); |
|
|
|
} |
|
|
|
UserBasicInfo userBasicInfo = result.getData(); |
|
|
|
if (userBasicInfo == null) { |
|
|
|
throw new RenException(String.format("根据userId:%s,没有查询到居民OpenId",userId)); |
|
|
|
} |
|
|
|
return userBasicInfo.getOpenId(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 查询工作人员openId |
|
|
|
* @return java.lang.String |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 14:46 |
|
|
|
*/ |
|
|
|
public String getWorkOpenId(String userId) { |
|
|
|
StaffBasicInfoFormDTO form = new StaffBasicInfoFormDTO(); |
|
|
|
form.setStaffId(userId); |
|
|
|
Result<StaffBasicInfo> result = epmetUserOpenFeignClient.getStaffBasicInfo(form); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException(String.format("查询工作人员OpenId失败,userId:%s,错误信息:%s",userId , result.getInternalMsg())); |
|
|
|
} |
|
|
|
StaffBasicInfo staffBasicInfo = result.getData(); |
|
|
|
if (staffBasicInfo == null) { |
|
|
|
throw new RenException(String.format("根据userId:%s,没有查询到工作人员OpenId",userId)); |
|
|
|
} |
|
|
|
return staffBasicInfo.getOpenId(); |
|
|
|
} |
|
|
|
} |