添加服务消息通知的消息记录和操作统计记录
This commit is contained in:
parent
b544639b11
commit
f73d950599
@ -10,7 +10,7 @@ public enum StatisticEnum {
|
|||||||
ON_SITE_PAYMENT(3,"现场支付"),
|
ON_SITE_PAYMENT(3,"现场支付"),
|
||||||
POST_PAYMENT(4,"事后支付"),
|
POST_PAYMENT(4,"事后支付"),
|
||||||
REFUND(5,"退款"),
|
REFUND(5,"退款"),
|
||||||
AGREE_TO_PUSH(6,"同意推送"),
|
MESSAGE_PUSH(6,"消息推送"),
|
||||||
DOWNLOAD(8,"下载"),
|
DOWNLOAD(8,"下载"),
|
||||||
CLICK_ON_PAYMENT(9,"点击支付、购买"),
|
CLICK_ON_PAYMENT(9,"点击支付、购买"),
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public interface MemberMapper {
|
|||||||
* 查询用户当前景区服务通知状态
|
* 查询用户当前景区服务通知状态
|
||||||
* @param scenicId 景区id
|
* @param scenicId 景区id
|
||||||
* @param memberId 用户id
|
* @param memberId 用户id
|
||||||
* @return
|
* @return 0关闭 1开启
|
||||||
*/
|
*/
|
||||||
Integer getScenicServiceNoticeStatus(@Param("scenicId") Long scenicId,@Param("memberId") Long memberId);
|
Integer getScenicServiceNoticeStatus(@Param("scenicId") Long scenicId,@Param("memberId") Long memberId);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.ycwl.basic.mapper;
|
package com.ycwl.basic.mapper;
|
||||||
|
|
||||||
|
import com.ycwl.basic.model.mobile.messageRecord.MessageRecordEntity;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,4 +9,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MessageRecordMapper {
|
public interface MessageRecordMapper {
|
||||||
|
|
||||||
|
int insertMessageRecord(MessageRecordEntity messageRecordEntity);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.ycwl.basic.model.mobile.messageRecord;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:longbinbin
|
||||||
|
* @Date:2024/12/13 11:37
|
||||||
|
* 景区服务消息记录表
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("message_record")
|
||||||
|
public class MessageRecordEntity {
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private Long memberId;
|
||||||
|
/**
|
||||||
|
* 景区id
|
||||||
|
*/
|
||||||
|
private Long scenicId;
|
||||||
|
/**
|
||||||
|
* 消息模板
|
||||||
|
*/
|
||||||
|
private String templateId;
|
||||||
|
/**
|
||||||
|
* 消息内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
private String createTime;
|
||||||
|
}
|
@ -41,7 +41,14 @@ public class WechatMessageSubscribeForm {
|
|||||||
* 进入小程序查看的语言类型:支持zh_CN、en_US、zh_HK、zh_TW,默认为zh_CN
|
* 进入小程序查看的语言类型:支持zh_CN、en_US、zh_HK、zh_TW,默认为zh_CN
|
||||||
*/
|
*/
|
||||||
private String lang;
|
private String lang;
|
||||||
|
/**
|
||||||
|
* 景区id
|
||||||
|
*/
|
||||||
|
private Long scenicId;
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private Long memberId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,19 @@ import com.ycwl.basic.config.WechatConfig;
|
|||||||
import com.ycwl.basic.constant.NumberConstant;
|
import com.ycwl.basic.constant.NumberConstant;
|
||||||
import com.ycwl.basic.constant.WeiXinConstant;
|
import com.ycwl.basic.constant.WeiXinConstant;
|
||||||
import com.ycwl.basic.enums.BizCodeEnum;
|
import com.ycwl.basic.enums.BizCodeEnum;
|
||||||
|
import com.ycwl.basic.enums.StatisticEnum;
|
||||||
import com.ycwl.basic.exception.AppException;
|
import com.ycwl.basic.exception.AppException;
|
||||||
|
import com.ycwl.basic.mapper.MemberMapper;
|
||||||
|
import com.ycwl.basic.mapper.MessageRecordMapper;
|
||||||
|
import com.ycwl.basic.mapper.ScenicMapper;
|
||||||
|
import com.ycwl.basic.mapper.StatisticsMapper;
|
||||||
|
import com.ycwl.basic.model.mobile.messageRecord.MessageRecordEntity;
|
||||||
|
import com.ycwl.basic.model.mobile.statistic.req.StatisticsRecordAddReq;
|
||||||
import com.ycwl.basic.model.wx.WechatAccessTokenVO;
|
import com.ycwl.basic.model.wx.WechatAccessTokenVO;
|
||||||
import com.ycwl.basic.model.wx.WechatMessageSubscribeForm;
|
import com.ycwl.basic.model.wx.WechatMessageSubscribeForm;
|
||||||
import com.ycwl.basic.model.wx.WechatMssVO;
|
import com.ycwl.basic.model.wx.WechatMssVO;
|
||||||
import com.ycwl.basic.service.mobile.WxNotifyService;
|
import com.ycwl.basic.service.mobile.WxNotifyService;
|
||||||
|
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -39,6 +47,12 @@ public class WxNotifyServiceImpl implements WxNotifyService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private WechatConfig wechatConfig;
|
private WechatConfig wechatConfig;
|
||||||
|
@Autowired
|
||||||
|
private MessageRecordMapper messageRecordMapper;
|
||||||
|
@Autowired
|
||||||
|
private StatisticsMapper statisticsMapper;
|
||||||
|
@Autowired
|
||||||
|
private MemberMapper memberMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存accessToken
|
* 缓存accessToken
|
||||||
@ -81,31 +95,58 @@ public class WxNotifyServiceImpl implements WxNotifyService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject pushMessage(WechatMessageSubscribeForm info) {
|
public JSONObject pushMessage(WechatMessageSubscribeForm info) {
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
|
||||||
String url = MESSAGE_SEND_URL + getAccessToken();
|
|
||||||
|
|
||||||
// 拼接推送的模板
|
Integer scenicServiceNoticeStatus = memberMapper.getScenicServiceNoticeStatus(info.getScenicId(), info.getMemberId());
|
||||||
WechatMssVO wxMssVO = new WechatMssVO();
|
if (scenicServiceNoticeStatus == NumberConstant.ZERO) {
|
||||||
wxMssVO.setTouser(info.getOpenId()); // 用户的openId
|
log.info("用户已关闭通知");
|
||||||
wxMssVO.setTemplate_id(info.getTemplateId()); // 订阅消息模板id
|
return null;
|
||||||
wxMssVO.setLang(info.getLang()); // 语言类型
|
}else {
|
||||||
wxMssVO.setMiniprogram_state(info.getMiniprogram_state()); // 跳转小程序类型
|
// 发送通知
|
||||||
wxMssVO.setPage(info.getPage());
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
String url = MESSAGE_SEND_URL + getAccessToken();
|
||||||
|
|
||||||
// // TODO: 推送的内容
|
// 拼接推送的模板
|
||||||
// Map<String, WechatTemplateData> map = new HashMap<>();
|
WechatMssVO wxMssVO = new WechatMssVO();
|
||||||
// map.put("msg", new WechatTemplateData("发消息了"));
|
wxMssVO.setTouser(info.getOpenId()); // 用户的openId
|
||||||
wxMssVO.setData(info.getData());
|
wxMssVO.setTemplate_id(info.getTemplateId()); // 订阅消息模板id
|
||||||
|
wxMssVO.setLang(info.getLang()); // 语言类型
|
||||||
|
wxMssVO.setMiniprogram_state(info.getMiniprogram_state()); // 跳转小程序类型
|
||||||
|
wxMssVO.setPage(info.getPage());
|
||||||
|
|
||||||
// 发送
|
// // TODO: 推送的内容
|
||||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, wxMssVO, String.class);
|
// Map<String, WechatTemplateData> map = new HashMap<>();
|
||||||
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody()));
|
// map.put("msg", new WechatTemplateData("发消息了"));
|
||||||
Integer errcode = jsonObject.getInteger(WECHAT_ERRCODE);
|
wxMssVO.setData(info.getData());
|
||||||
String errmsg = jsonObject.getString(WECHAT_ERRMSG);
|
|
||||||
if (errcode != NumberConstant.ZERO) {
|
// 发送
|
||||||
throw new AppException(errcode, errmsg);
|
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, wxMssVO, String.class);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody()));
|
||||||
|
Integer errcode = jsonObject.getInteger(WECHAT_ERRCODE);
|
||||||
|
String errmsg = jsonObject.getString(WECHAT_ERRMSG);
|
||||||
|
if (errcode != NumberConstant.ZERO) {
|
||||||
|
throw new AppException(errcode, errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录消息记录
|
||||||
|
MessageRecordEntity messageRecord = new MessageRecordEntity();
|
||||||
|
messageRecord.setId(SnowFlakeUtil.getLongId());
|
||||||
|
messageRecord.setMemberId(info.getMemberId());
|
||||||
|
messageRecord.setScenicId(info.getScenicId());
|
||||||
|
messageRecord.setTemplateId(info.getTemplateId());
|
||||||
|
messageRecord.setContent(info.getData().toString());
|
||||||
|
messageRecordMapper.insertMessageRecord(messageRecord);
|
||||||
|
|
||||||
|
// 统计消息记录
|
||||||
|
StatisticsRecordAddReq statisticsRecordAddReq = new StatisticsRecordAddReq();
|
||||||
|
statisticsRecordAddReq.setScenicId(info.getScenicId());
|
||||||
|
statisticsRecordAddReq.setMemberId(info.getMemberId());
|
||||||
|
statisticsRecordAddReq.setType(StatisticEnum.MESSAGE_PUSH.code);
|
||||||
|
statisticsRecordAddReq.setMorphId(messageRecord.getId());
|
||||||
|
statisticsMapper.addStatisticsRecord(statisticsRecordAddReq);
|
||||||
|
|
||||||
|
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody()));
|
||||||
}
|
}
|
||||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.ycwl.basic.mapper.MessageRecordMapper">
|
<mapper namespace="com.ycwl.basic.mapper.MessageRecordMapper">
|
||||||
|
|
||||||
|
<insert id="insertMessageRecord">
|
||||||
|
insert into message_record (id,member_id,scenic_id,template_id,context)
|
||||||
|
value (#{id},#{memberId},#{scenicId},#{templateId},#{content})
|
||||||
|
</insert>
|
||||||
</mapper>
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user