fix(通知):修改通知逻辑

This commit is contained in:
2025-05-14 16:06:03 +08:00
parent b75884743f
commit ee0a877345
16 changed files with 208 additions and 89 deletions
+1
View File
@@ -99,6 +99,7 @@
<artifactId>hutool-all</artifactId>
<version>5.8.25</version>
</dependency>
</dependencies>
<build>
@@ -4,12 +4,10 @@ import com.alibaba.fastjson.JSONObject;
import com.central.device.service.LiveStreamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/live")
public class LiveStreamController {
@Autowired
@@ -4,10 +4,10 @@ server:
spring:
application:
name: file-center
cloud:
nacos:
discovery:
ip: 119.45.169.13
# cloud:
# nacos:
# discovery:
# ip: 119.45.169.13
servlet:
multipart:
max-file-size: 20MB
+6
View File
@@ -113,6 +113,12 @@
<artifactId>weixin-java-miniapp</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-common</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@@ -0,0 +1,9 @@
package com.central.order.config;
import lombok.Data;
@Data
public class WxMaProperties {
private String appId;
private String secret;
}
@@ -1,5 +1,8 @@
package com.central.order.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.api.WxMpService;
@@ -46,4 +49,20 @@ public class WxMpConfiguration {
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
@Bean
@ConfigurationProperties(prefix = "wx.mini")
public WxMaProperties wxMaProperties() {
return new WxMaProperties();
}
@Bean
public WxMaService wxMaService(WxMaProperties wxMaProperties) {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(wxMaProperties.getAppId());
config.setSecret(wxMaProperties.getSecret());
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
return service;
}
}
@@ -10,6 +10,7 @@ import com.central.order.model.*;
import com.central.order.model.dto.CallbackDTO;
import com.central.order.model.params.EditTaskQueryParams;
import com.central.order.service.*;
import com.central.order.util.DateUtils;
import com.central.order.util.StringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -184,7 +185,7 @@ public class AutoCutVideoController {
}
Tourism tourism = tourismService.getTourismById(order.getTourismId());
String result = "您的视频已制作完成,可前往相册页查看和下载!";
String result = "视频已生成请查阅";
wxMiniSubscribeService.sendPaySuccessMsg(
user.getOpenId(),
@@ -192,7 +193,7 @@ public class AutoCutVideoController {
orderNo,
result,
StringUtils.fenToYuan(order.getOrderAmount()),
order.getPayTime().toString()
DateUtils.sdf.format(order.getPayTime())
);
log.info("已发送一键成片完成通知: userId={}, openId={}, orderNo={}", userId, user.getOpenId(), orderNo);
} catch (Exception e) {
@@ -28,6 +28,6 @@ public interface DeviceCenterService {
@GetMapping("/wayline/sign/{id}")
String getLineFileSign(@PathVariable("id") String id);
@GetMapping("/live/stream-urls")
@GetMapping("/stream-urls")
JSONObject getStreamUrls(@RequestParam("deviceId") String deviceId) ;
}
@@ -10,6 +10,7 @@ import com.central.order.event.OrderStatusChangeEvent;
import com.central.order.feign.UserCenterService;
import com.central.order.model.*;
import com.central.order.service.*;
import com.central.order.util.DateUtils;
import com.central.order.util.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -154,7 +155,7 @@ public class OrderStatusChangeListener {
/**
* 处理支付成功逻辑
*/
private void handlePaymentSuccess(Order order, Tourism tourism) {
try {
// 1. 发送微信通知
@@ -165,8 +166,7 @@ public class OrderStatusChangeListener {
// 发送小程序订阅消息
if (sysUser.getOpenId() != null) {
String payTime = order.getPayTime() != null ? order.getPayTime().toString() : "";
String tip = "您的订单已支付成功,您当前排在第"+queue+"位,欢迎体验!";
String tip = "支付成功,当前排第"+queue+"位";
String amount = StringUtils.fenToYuan(order.getOrderAmount());
String orderName = tourism.getTourismName();
wxMiniSubscribeService.sendPaySuccessMsg(
@@ -175,7 +175,7 @@ public class OrderStatusChangeListener {
order.getOrderNo(),
tip,
amount,
payTime
DateUtils.sdf.format(order.getPayTime())
);
}
@@ -225,7 +225,7 @@ public class OrderStatusChangeListener {
Tourism tourism = tourismService.getTourismById(nextOrder.getTourismId());
if (nextUser != null && nextUser.getOpenId() != null && tourism != null) {
String activityName = tourism.getTourismName(); // 活动名称
String remark = "请您准备,当前排队序列的下一位就轮到您啦!";
String remark = "即将为您进行拍摄服务";
String activityNo = nextOrder.getOrderNo(); // 活动编号
wxMiniSubscribeService.sendPaySuccessMsg(
nextUser.getOpenId(),
@@ -233,7 +233,7 @@ public class OrderStatusChangeListener {
activityNo,
remark,
activityNo,
nextOrder.getPayTime().toString()
DateUtils.sdf.format(nextOrder.getPayTime())
);
log.info("已通知下一个排队用户: userId={}, openId={}, orderNo={}", nextUser.getId(), nextUser.getOpenId(), activityNo);
}
@@ -21,4 +21,15 @@ public interface WxMiniSubscribeService {
* 一键成片制作完成通知
*/
void sendVideoEditCompleteMsg(String openId, String taskName, String orderNo, String result);
/**
* 服务进度提醒订阅消息
* @param openId
* @param taskName
* @param processDesc
* @param orderNo
* @param orderTime
* @param result
*/
void sendServiceProcessMsg(String openId, String taskName,String processDesc, String orderNo,String orderTime, String result, String pageUrl);
}
@@ -2,13 +2,18 @@ package com.central.order.service.impl;
import com.central.common.exception.BusinessException;
import com.central.common.model.FileInfo;
import com.central.common.model.SysUser;
import com.central.order.constants.EditTaskStatus;
import com.central.order.feign.FileCenterService;
import com.central.order.feign.UserCenterService;
import com.central.order.model.EditTask;
import com.central.order.model.Order;
import com.central.order.model.OrderFile;
import com.central.order.model.Tourism;
import com.central.order.model.dto.VideoEditStatus;
import com.central.order.service.*;
import com.central.order.util.DateUtils;
import com.central.order.util.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +40,12 @@ public class VideoEditServiceImpl implements IVideoEditService {
private FileCenterService fileCenterService;
@Autowired
private IOrderService orderService;
@Autowired
private UserCenterService userCenterService;
@Autowired
private ITourismService tourismService;
@Autowired
private WxMiniSubscribeService wxMiniSubscribeService;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -108,6 +119,10 @@ public class VideoEditServiceImpl implements IVideoEditService {
log.info("视频编辑任务处理完成: jobId={}, orderNo={}, outputUrl={}",
jobId, task.getOrderSn(), outputUrl);
// 发送小程序通知
notifyUser(task.getUserId(),task.getOrderSn());
} catch (Exception e) {
log.error("处理任务成功状态失败: jobId={}", jobId, e);
throw new BusinessException("处理任务成功状态失败: " + e.getMessage());
@@ -163,4 +178,37 @@ public class VideoEditServiceImpl implements IVideoEditService {
}
}
private void notifyUser(Long userId,String orderNo) {
try {
// 1. 获取用户信息
SysUser user = userCenterService.findUserById(userId);
if (user == null || user.getOpenId() == null) {
log.warn("未找到用户或用户未绑定小程序openId,无法发送成片完成通知: userId={}", userId);
return;
}
// 2. 获取任务和订单信息
// 假设 message 里包含订单号或任务名,实际可根据 EditTask 查找
Order order = orderService.getOrderByNumber(orderNo);
if (order == null) {
log.warn("未找到订单信息,无法发送成片完成通知: orderNo={}", orderNo);
return;
}
Tourism tourism = tourismService.getTourismById(order.getTourismId());
String result = "视频已生成请查阅";
wxMiniSubscribeService.sendPaySuccessMsg(
user.getOpenId(),
tourism.getTourismName(),
orderNo,
result,
StringUtils.fenToYuan(order.getOrderAmount()),
DateUtils.sdf.format(order.getPayTime())
);
log.info("已发送一键成片完成通知: userId={}, openId={}, orderNo={}", userId, user.getOpenId(), orderNo);
} catch (Exception e) {
log.error("发送一键成片完成通知失败: userId={}, message={}", userId, orderNo, e);
}
}
}
@@ -1,16 +1,16 @@
package com.central.order.service.impl;
import com.central.order.service.IWxAccessTokenService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.central.order.service.WxMiniSubscribeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
@@ -18,43 +18,28 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
@Value("${wx.mini.template.pay-success}")
private String templateId;
@Value("${wx.mini.template.activity-start}")
private String activityStartTemplateId;
@Value("${wx.mini.template.video-edit-complete}")
private String videoEditCompleteTemplateId;
@Resource
private RestTemplate restTemplate;
@Autowired
private IWxAccessTokenService wxAccessTokenService;
private WxMaService wxMaService;
// @Retryable(value = {ConnectException.class, SocketTimeoutException.class},
// maxAttempts = 3,
// backoff = @Backoff(delay = 2000))
@Override
public void sendPaySuccessMsg(String openId, String orderName, String orderNo, String tip, String amount, String orderTime) {
try {
String accessToken = wxAccessTokenService.getAccessToken();
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken;
WxMaSubscribeMessage msg = new WxMaSubscribeMessage();
msg.setToUser(openId);
msg.setTemplateId(templateId);
msg.setPage("pages/task/task"); // 可选跳转页面
List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>();
dataList.add(new WxMaSubscribeMessage.MsgData("thing1", orderName)); // 订单名称
dataList.add(new WxMaSubscribeMessage.MsgData("character_string2", orderNo)); // 订单编号
dataList.add(new WxMaSubscribeMessage.MsgData("thing4", tip)); // 温馨提示
dataList.add(new WxMaSubscribeMessage.MsgData("amount9", amount)); // 已付金额
dataList.add(new WxMaSubscribeMessage.MsgData("time10", orderTime)); // 下单时间
msg.setData(dataList);
Map<String, Object> data = new HashMap<>();
data.put("thing1", Map.of("value", orderName)); // 订单名称
data.put("character_string2", Map.of("value", orderNo)); // 订单编号
data.put("thing4", Map.of("value", tip)); // 温馨提示
data.put("amount9", Map.of("value", amount)); // 已付金额
data.put("time10", Map.of("value", orderTime)); // 下单时间
Map<String, Object> body = new HashMap<>();
body.put("touser", openId);
body.put("template_id", templateId);
body.put("data", data);
body.put("page", "pages/task/task"); // 可选跳转
String resp = restTemplate.postForObject(url, body, String.class);
log.info("小程序支付成功订阅消息发送结果: {}", resp);
wxMaService.getSubscribeService().sendSubscribeMsg(msg);
log.info("小程序支付成功订阅消息发送成功: openId={}, orderNo={}", openId, orderNo);
} catch (Exception e) {
log.error("小程序支付成功订阅消息发送失败: openId={}, orderNo={}, error={}", openId, orderNo, e.getMessage(), e);
}
@@ -62,48 +47,34 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService {
@Override
public void sendActivityStartMsg(String openId, String place, String activityName, String remark, String activityNo) {
try {
String accessToken = wxAccessTokenService.getAccessToken();
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken;
Map<String, Object> data = new HashMap<>();
data.put("thing4", Map.of("value", place)); // 活动地点
data.put("thing1", Map.of("value", activityName)); // 活动名称
data.put("thing5", Map.of("value", remark)); // 备注
data.put("character_string10", Map.of("value", activityNo)); // 活动编号
Map<String, Object> body = new HashMap<>();
body.put("touser", openId);
body.put("template_id", activityStartTemplateId);
body.put("data", data);
String resp = restTemplate.postForObject(url, body, String.class);
log.info("小程序活动即将开始提醒发送结果: {}", resp);
} catch (Exception e) {
log.error("小程序活动即将开始提醒发送失败: openId={}, activityNo={}, error={}", openId, activityNo, e.getMessage(), e);
}
}
@Override
public void sendVideoEditCompleteMsg(String openId, String taskName, String orderNo, String result) {
}
@Override
public void sendServiceProcessMsg(String openId, String taskName, String processDesc, String orderNo, String orderTime, String result, String pageUrl) {
try {
String accessToken = wxAccessTokenService.getAccessToken();
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken;
WxMaSubscribeMessage msg = new WxMaSubscribeMessage();
msg.setToUser(openId);
msg.setTemplateId(templateId);
msg.setPage(pageUrl); // 可选跳转页面 "pages/task/task"
Map<String, Object> data = new HashMap<>();
data.put("thing7", Map.of("value", taskName)); // 任务名称
data.put("character_string13", Map.of("value", orderNo)); // 订单编号
data.put("thing14", Map.of("value", result)); // 制作结果
List<WxMaSubscribeMessage.MsgData> dataList = new ArrayList<>();
dataList.add(new WxMaSubscribeMessage.MsgData("thing1", taskName)); // 服务名称
dataList.add(new WxMaSubscribeMessage.MsgData("character_string2", orderNo)); // 订单编号
dataList.add(new WxMaSubscribeMessage.MsgData("thing4", processDesc)); // 服务阶段
dataList.add(new WxMaSubscribeMessage.MsgData("time8", orderTime)); // 已付金额
dataList.add(new WxMaSubscribeMessage.MsgData("thing6", result)); // 备注
msg.setData(dataList);
Map<String, Object> body = new HashMap<>();
body.put("touser", openId);
body.put("template_id", videoEditCompleteTemplateId);
body.put("data", data);
String resp = restTemplate.postForObject(url, body, String.class);
log.info("小程序一键成片完成通知发送结果: {}", resp);
wxMaService.getSubscribeService().sendSubscribeMsg(msg);
log.info("小程序服务进度订阅消息发送成功: openId={}, orderNo={}", openId, orderNo);
} catch (Exception e) {
log.error("小程序一键成片完成通知发送失败: openId={}, orderNo={}, error={}", openId, orderNo, e.getMessage(), e);
log.error("小程序服务进度订阅消息发送失败: openId={}, orderNo={}, error={}", openId, orderNo, e.getMessage(), e);
}
}
}
@@ -26,7 +26,24 @@ knife4j:
enable: true
setting:
swagger-model-name: 订单中心接口文档
zlt:
#多租户配置
tenant:
enable: false
ignoreTables:
- edit_task
- home_carousel
- sys_message
- wx_message_record
- wx_subscribe_status
- video_template
- profit_sharing
- order_statistics
ignoreSqls:
# 用户关联角色时,显示所有角色
- com.central.order.mapper.findList
# 用户列表显示用户所关联的所有角色
- com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
# 微信支付商户号
tencent:
merchantId: ${zlt.wxpay.merchantId}
@@ -99,6 +116,7 @@ wx:
secret: ${zlt.security.tencent.app-secret}
template:
pay-success: nSy7NGq1443YCfhgR81fgkeOVv9cSM5Ysp3nMoQYVpc
service-process: rgQCI3fMKPpgO-9nO3TzP-omohraGxX2suVioq7hQhk
activity-start: lgwkRnbdDc3mEwk3RMob43LpLHnLfglZtTkbFRPsPCA
order-complete: ZeIlAA6ImQLxBiLmo-53lM7wkL4KnuKKTGKWBZwYAdM
video-edit-complete: IXpL-Voztm3GM-zFj3sxA39qy8oRtAcxTiT7_Qsyz9Q
@@ -1,11 +1,11 @@
########################## 统一变量配置 ##########################
##### 数据库配置
#zlt.datasource.ip=127.0.0.1
#zlt.datasource.username=root
#zlt.datasource.password=root
zlt.datasource.ip=sh-cdb-i6yxaaec.sql.tencentcdb.com:58797
zlt.datasource.ip=127.0.0.1
zlt.datasource.username=root
zlt.datasource.password=ZXC_zxc!@#123+
zlt.datasource.password=root
#zlt.datasource.ip=sh-cdb-i6yxaaec.sql.tencentcdb.com:58797
#zlt.datasource.username=root
#zlt.datasource.password=ZXC_zxc!@#123+
##### redis配置
spring.data.redis.host=192.168.2.20
@@ -65,4 +65,18 @@
&:hover, &:focus {
border-color: #1890ff;
}
}
.imageList {
display: flex;
flex-wrap: wrap;
gap: 8px;
:global {
.ant-image {
border-radius: 4px;
overflow: hidden;
border: 1px solid #f0f0f0;
}
}
}
@@ -4,7 +4,7 @@ import {
ProFormSelect,
ProFormTextArea,
} from '@ant-design/pro-components';
import { Typography, Descriptions, Space, Tag } from 'antd';
import { Typography, Descriptions, Space, Tag, Image } from 'antd';
import React from 'react';
import { ORDER_STATUS, REFUND_STATUS } from '../constants';
import styles from './UpdateForm.less';
@@ -63,6 +63,29 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
{REFUND_STATUS[values?.state]?.text || '未知状态'}
</Tag>
</Descriptions.Item>
<Descriptions.Item label="退款原因" span={2}>
{values?.refundReason || '-'}
</Descriptions.Item>
<Descriptions.Item label="退款图片" span={2}>
{values?.refundImgs ? (
<div className={styles.imageList}>
{values.refundImgs.split(',').map((url: string, index: number) => (
<Image
key={index}
src={url}
width={100}
height={100}
style={{ marginRight: 8, marginBottom: 8 }}
preview={{
src: url,
}}
/>
))}
</div>
) : (
'-'
)}
</Descriptions.Item>
<Descriptions.Item label="申请时间" span={2}>
{values?.createTime}
</Descriptions.Item>