|
|
@@ -18,10 +18,20 @@ import org.springframework.web.client.HttpServerErrorException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import shop.alien.entity.store.LawyerConsultationOrder;
|
|
|
import shop.alien.entity.store.LawyerUserViolation;
|
|
|
+import shop.alien.entity.store.LifeNotice;
|
|
|
+import shop.alien.entity.store.LifeUser;
|
|
|
+import shop.alien.entity.store.LawyerUser;
|
|
|
+import shop.alien.entity.store.StoreUser;
|
|
|
+import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
+import shop.alien.lawyer.config.WebSocketProcess;
|
|
|
import shop.alien.lawyer.service.AiUserAuditTaskService;
|
|
|
import shop.alien.lawyer.service.LawyerUserViolationService;
|
|
|
import shop.alien.lawyer.util.ali.AliApi;
|
|
|
import shop.alien.mapper.LawyerConsultationOrderMapper;
|
|
|
+import shop.alien.mapper.LifeNoticeMapper;
|
|
|
+import shop.alien.mapper.LifeUserMapper;
|
|
|
+import shop.alien.mapper.LawyerUserMapper;
|
|
|
+import shop.alien.mapper.StoreUserMapper;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
@@ -53,6 +63,18 @@ public class AiUserAuditTaskServiceImpl implements AiUserAuditTaskService {
|
|
|
|
|
|
private final AliApi aliApi;
|
|
|
|
|
|
+ private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
+
|
|
|
+ private final WebSocketProcess webSocketProcess;
|
|
|
+
|
|
|
+ private final LifeUserMapper lifeUserMapper;
|
|
|
+
|
|
|
+ private final LawyerUserMapper lawyerUserMapper;
|
|
|
+
|
|
|
+ private final StoreUserMapper storeUserMapper;
|
|
|
+
|
|
|
+ private static final String SYSTEM_SENDER_ID = "system";
|
|
|
+
|
|
|
@Override
|
|
|
@Async("lawyerTaskExecutor")
|
|
|
public void asyncCallUserAuditTask(Map<String, Object> requestBody, String accessToken) {
|
|
|
@@ -185,7 +207,13 @@ public class AiUserAuditTaskServiceImpl implements AiUserAuditTaskService {
|
|
|
if (processingStatus != null) {
|
|
|
if (processingStatus == 1 && StringUtils.hasText(orderNumber)) {
|
|
|
// processing_status = 1 表示已通过,进行退款操作
|
|
|
- processRefund(orderNumber);
|
|
|
+ processRefund(orderNumber);
|
|
|
+
|
|
|
+ // 发送举报成功通知
|
|
|
+ //sendReportSuccessNotifications(orderNumber);
|
|
|
+ } else if (processingStatus == 2 && StringUtils.hasText(orderNumber)) {
|
|
|
+ // processing_status = 2 表示未违规(举报失败),发送举报失败通知
|
|
|
+ //sendReportFailureNotification(orderNumber, decisionReason);
|
|
|
}
|
|
|
} else {
|
|
|
log.warn("processing_status为空,订单号:{}", orderNumber);
|
|
|
@@ -268,5 +296,324 @@ public class AiUserAuditTaskServiceImpl implements AiUserAuditTaskService {
|
|
|
throw new RuntimeException("处理订单退款时发生异常,订单号:" + orderNumber + ",异常信息:" + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送举报失败通知
|
|
|
+ * <p>
|
|
|
+ * 当举报审核未通过时,向举报用户发送通知
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param orderNumber 订单号
|
|
|
+ * @param decisionReason 拒绝原因
|
|
|
+ */
|
|
|
+ private void sendReportFailureNotification(String orderNumber, String decisionReason) {
|
|
|
+ try {
|
|
|
+ // 根据订单号查询最新的举报记录
|
|
|
+ LambdaQueryWrapper<LawyerUserViolation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LawyerUserViolation::getOrderNumber, orderNumber)
|
|
|
+ .orderByDesc(LawyerUserViolation::getId)
|
|
|
+ .last("LIMIT 1");
|
|
|
+
|
|
|
+ LawyerUserViolation violation = lawyerUserViolationService.getOne(queryWrapper);
|
|
|
+ if (violation == null) {
|
|
|
+ log.warn("未找到举报记录,订单号:{}", orderNumber);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取举报人接收ID
|
|
|
+ String receiverId = getReporterReceiverId(violation);
|
|
|
+ if (!StringUtils.hasText(receiverId)) {
|
|
|
+ log.warn("获取举报人接收ID失败,举报ID:{}", violation.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取举报理由文本
|
|
|
+ String violationReasonText = getViolationReasonText(violation);
|
|
|
+
|
|
|
+ // 构建通知内容
|
|
|
+ StringBuilder messageBuilder = new StringBuilder();
|
|
|
+ messageBuilder.append("您举报律师").append(violationReasonText)
|
|
|
+ .append(",经核实,不存在此行为,订单金额不予退还。");
|
|
|
+
|
|
|
+ // 添加拒绝原因
|
|
|
+ if (StringUtils.hasText(decisionReason)) {
|
|
|
+ messageBuilder.append("拒绝原因:").append(decisionReason);
|
|
|
+ } else {
|
|
|
+ // 如果没有拒绝原因,使用默认值
|
|
|
+ messageBuilder.append("拒绝原因:举报不实");
|
|
|
+ }
|
|
|
+
|
|
|
+ String message = messageBuilder.toString();
|
|
|
+
|
|
|
+ // 创建并保存通知
|
|
|
+ LifeNotice lifeNotice = createLifeNotice(violation.getId(), receiverId, "举报失败通知", message);
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+
|
|
|
+ // 发送WebSocket消息
|
|
|
+ sendWebSocketMessage(receiverId, lifeNotice);
|
|
|
+
|
|
|
+ log.info("举报失败通知发送成功,订单号:{},接收人ID:{}", orderNumber, receiverId);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送举报失败通知异常,订单号:{},异常信息:{}", orderNumber, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送举报成功通知
|
|
|
+ * <p>
|
|
|
+ * 当举报审核通过时,向举报用户和被举报律师发送通知
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param orderNumber 订单号
|
|
|
+ */
|
|
|
+ private void sendReportSuccessNotifications(String orderNumber) {
|
|
|
+ try {
|
|
|
+ // 根据订单号查询最新的举报记录
|
|
|
+ LambdaQueryWrapper<LawyerUserViolation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LawyerUserViolation::getOrderNumber, orderNumber).eq(LawyerUserViolation::getDeleteFlag, 0)
|
|
|
+ .orderByDesc(LawyerUserViolation::getId)
|
|
|
+ .last("LIMIT 1");
|
|
|
+
|
|
|
+ LawyerUserViolation violation = lawyerUserViolationService.getOne(queryWrapper);
|
|
|
+ if (violation == null) {
|
|
|
+ log.warn("未找到举报记录,订单号:{}", orderNumber);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送举报人通知
|
|
|
+ sendReporterNotification(violation);
|
|
|
+
|
|
|
+ // 发送被举报人通知
|
|
|
+ sendReportedNotification(violation, orderNumber);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送举报成功通知异常,订单号:{},异常信息:{}", orderNumber, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送举报人通知
|
|
|
+ *
|
|
|
+ * @param violation 举报记录
|
|
|
+ */
|
|
|
+ private void sendReporterNotification(LawyerUserViolation violation) {
|
|
|
+ try {
|
|
|
+ // 获取举报人接收ID
|
|
|
+ String receiverId = getReporterReceiverId(violation);
|
|
|
+ if (!StringUtils.hasText(receiverId)) {
|
|
|
+ log.warn("获取举报人接收ID失败,举报ID:{}", violation.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取举报理由文本
|
|
|
+ String violationReasonText = getViolationReasonText(violation);
|
|
|
+
|
|
|
+ // 构建通知内容
|
|
|
+ String message = String.format("您举报律师%s,经核实,确实存在此行为,订单金额将在1-3个工作日原路返还,请注意查收。",
|
|
|
+ violationReasonText);
|
|
|
+
|
|
|
+ // 创建并保存通知
|
|
|
+ LifeNotice lifeNotice = createLifeNotice(violation.getId(), receiverId, "举报成功通知", message);
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+
|
|
|
+ // 发送WebSocket消息
|
|
|
+ sendWebSocketMessage(receiverId, lifeNotice);
|
|
|
+
|
|
|
+ log.info("举报人通知发送成功,订单号:{},接收人ID:{}", violation.getOrderNumber(), receiverId);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送举报人通知异常,举报ID:{},异常信息:{}", violation.getId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送被举报人通知
|
|
|
+ *
|
|
|
+ * @param violation 举报记录
|
|
|
+ * @param orderNumber 订单号
|
|
|
+ */
|
|
|
+ private void sendReportedNotification(LawyerUserViolation violation, String orderNumber) {
|
|
|
+ try {
|
|
|
+ // 获取被举报人接收ID
|
|
|
+ String receiverId = getReportedReceiverId(violation);
|
|
|
+ if (!StringUtils.hasText(receiverId)) {
|
|
|
+ log.warn("获取被举报人接收ID失败,举报ID:{}", violation.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建通知内容
|
|
|
+ String message = String.format("用户对编号为%s的订单进行申诉,经核实,用户举报属实,订单金额将会退还给用户。",
|
|
|
+ orderNumber);
|
|
|
+
|
|
|
+ // 创建并保存通知
|
|
|
+ LifeNotice lifeNotice = createLifeNotice(violation.getId(), receiverId, "被举报成功通知", message);
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+
|
|
|
+ // 发送WebSocket消息
|
|
|
+ sendWebSocketMessage(receiverId, lifeNotice);
|
|
|
+
|
|
|
+ log.info("被举报人通知发送成功,订单号:{},接收人ID:{}", orderNumber, receiverId);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送被举报人通知异常,举报ID:{},异常信息:{}", violation.getId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取举报理由文本
|
|
|
+ *
|
|
|
+ * @param violation 举报记录
|
|
|
+ * @return 举报理由文本
|
|
|
+ */
|
|
|
+ private String getViolationReasonText(LawyerUserViolation violation) {
|
|
|
+ String violationReasonId = violation.getViolationReason();
|
|
|
+ if (!StringUtils.hasText(violationReasonId)) {
|
|
|
+ return "其他原因";
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (violationReasonId) {
|
|
|
+ case "1":
|
|
|
+ return "服务态度差";
|
|
|
+ case "2":
|
|
|
+ return "专业能力差";
|
|
|
+ case "3":
|
|
|
+ return "响应时间超过24小时";
|
|
|
+ case "4":
|
|
|
+ // 其他原因,使用用户填写的内容
|
|
|
+ String otherReason = violation.getOtherReasonContent();
|
|
|
+ return StringUtils.hasText(otherReason) ? otherReason : "其他原因";
|
|
|
+ default:
|
|
|
+ return "其他原因";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取举报人接收ID
|
|
|
+ *
|
|
|
+ * @param violation 举报记录
|
|
|
+ * @return 接收人ID,格式:lawyer_/store_/user_ + 手机号
|
|
|
+ */
|
|
|
+ private String getReporterReceiverId(LawyerUserViolation violation) {
|
|
|
+ String reportingUserType = violation.getReportingUserType();
|
|
|
+ String reportingUserId = violation.getReportingUserId();
|
|
|
+
|
|
|
+ if (!StringUtils.hasText(reportingUserId)) {
|
|
|
+ log.warn("举报用户ID为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户类型:1-商户用户,2-普通用户,3-律师用户
|
|
|
+ if ("3".equals(reportingUserType)) {
|
|
|
+ // 律师用户
|
|
|
+ LawyerUser lawyerUser = lawyerUserMapper.selectById(reportingUserId);
|
|
|
+ if (lawyerUser != null && StringUtils.hasText(lawyerUser.getPhone())) {
|
|
|
+ return "lawyer_" + lawyerUser.getPhone();
|
|
|
+ }
|
|
|
+ } else if ("1".equals(reportingUserType)) {
|
|
|
+ // 商户用户
|
|
|
+ StoreUser storeUser = storeUserMapper.selectById(reportingUserId);
|
|
|
+ if (storeUser != null && StringUtils.hasText(storeUser.getPhone())) {
|
|
|
+ return "store_" + storeUser.getPhone();
|
|
|
+ }
|
|
|
+ } else if ("2".equals(reportingUserType)) {
|
|
|
+ // 普通用户
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(reportingUserId);
|
|
|
+ if (lifeUser != null && StringUtils.hasText(lifeUser.getUserPhone())) {
|
|
|
+ return "user_" + lifeUser.getUserPhone();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("获取举报人手机号失败,用户类型:{},用户ID:{}", reportingUserType, reportingUserId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取被举报人接收ID
|
|
|
+ *
|
|
|
+ * @param violation 举报记录
|
|
|
+ * @return 接收人ID,格式:lawyer_/store_/user_ + 手机号
|
|
|
+ */
|
|
|
+ private String getReportedReceiverId(LawyerUserViolation violation) {
|
|
|
+ String reportedUserType = violation.getReportedUserType();
|
|
|
+ String reportedUserId = violation.getReportedUserId();
|
|
|
+
|
|
|
+ if (!StringUtils.hasText(reportedUserId)) {
|
|
|
+ log.warn("被举报用户ID为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户类型:1-商户用户,2-普通用户,3-律师用户
|
|
|
+ if ("3".equals(reportedUserType)) {
|
|
|
+ // 律师用户
|
|
|
+ LawyerUser lawyerUser = lawyerUserMapper.selectById(reportedUserId);
|
|
|
+ if (lawyerUser != null && StringUtils.hasText(lawyerUser.getPhone())) {
|
|
|
+ return "lawyer_" + lawyerUser.getPhone();
|
|
|
+ }
|
|
|
+ } else if ("1".equals(reportedUserType)) {
|
|
|
+ // 商户用户
|
|
|
+ StoreUser storeUser = storeUserMapper.selectById(reportedUserId);
|
|
|
+ if (storeUser != null && StringUtils.hasText(storeUser.getPhone())) {
|
|
|
+ return "store_" + storeUser.getPhone();
|
|
|
+ }
|
|
|
+ } else if ("2".equals(reportedUserType)) {
|
|
|
+ // 普通用户
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(reportedUserId);
|
|
|
+ if (lifeUser != null && StringUtils.hasText(lifeUser.getUserPhone())) {
|
|
|
+ return "user_" + lifeUser.getUserPhone();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("获取被举报人手机号失败,用户类型:{},用户ID:{}", reportedUserType, reportedUserId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建通知对象
|
|
|
+ *
|
|
|
+ * @param businessId 业务ID(举报ID)
|
|
|
+ * @param receiverId 接收人ID
|
|
|
+ * @param title 通知标题
|
|
|
+ * @param message 通知消息
|
|
|
+ * @return 通知对象
|
|
|
+ */
|
|
|
+ private LifeNotice createLifeNotice(Integer businessId, String receiverId, String title, String message) {
|
|
|
+ LifeNotice lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId(SYSTEM_SENDER_ID);
|
|
|
+ lifeNotice.setBusinessId(businessId);
|
|
|
+ lifeNotice.setReceiverId(receiverId);
|
|
|
+ lifeNotice.setTitle(title);
|
|
|
+ lifeNotice.setNoticeType(1);
|
|
|
+ lifeNotice.setIsRead(0);
|
|
|
+ lifeNotice.setBusinessType(1);
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("message", message);
|
|
|
+ lifeNotice.setContext(jsonObject.toJSONString());
|
|
|
+
|
|
|
+ return lifeNotice;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送WebSocket消息
|
|
|
+ *
|
|
|
+ * @param receiverId 接收人ID
|
|
|
+ * @param lifeNotice 通知对象
|
|
|
+ */
|
|
|
+ private void sendWebSocketMessage(String receiverId, LifeNotice lifeNotice) {
|
|
|
+ try {
|
|
|
+ WebSocketVo webSocketVo = new WebSocketVo();
|
|
|
+ webSocketVo.setSenderId(SYSTEM_SENDER_ID);
|
|
|
+ webSocketVo.setReceiverId(receiverId);
|
|
|
+ webSocketVo.setCategory("notice");
|
|
|
+ webSocketVo.setNoticeType("1");
|
|
|
+ webSocketVo.setIsRead(0);
|
|
|
+ webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
+
|
|
|
+ webSocketProcess.sendMessage(receiverId, JSONObject.from(webSocketVo).toJSONString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送WebSocket消息异常,接收人ID:{},异常信息:{}", receiverId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|