From 9e9b3a5cb576392a8ef015d89ec67ddbf9919129 Mon Sep 17 00:00:00 2001 From: dzq Date: Mon, 21 Jul 2025 11:11:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(DeadlineOrderJob):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=80=BE=E6=9C=9F=E8=AE=A2=E5=8D=95=E5=A4=84=E7=90=86=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在QywxScheduleJob中添加日志记录微信用户信息 - 重构DeadlineOrderJob,添加企业微信通知功能 - 将创建操作日志和发送通知逻辑提取为独立方法 - 修复订单创建时间引用错误问题 --- .../customize/service/QywxScheduleJob.java | 2 + .../service/job/DeadlineOrderJob.java | 78 ++++++++++++++++--- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java b/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java index 4c3e35c..ca2391f 100644 --- a/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java +++ b/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java @@ -459,6 +459,8 @@ public class QywxScheduleJob { List toAdd = wxUsers.stream() .filter(wxUser -> !existingUserIds.contains(wxUser.getUserid())) .collect(Collectors.toList()); + log.info("wxUsers: {}", JSONUtil.toJsonStr(wxUsers)); + log.info("existingUserIds: {}", JSONUtil.toJsonStr(existingUserIds)); log.info("syncUserInfo toAdd: {}", JSONUtil.toJsonStr(toAdd)); // 识别需要删除的用户 diff --git a/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/job/DeadlineOrderJob.java b/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/job/DeadlineOrderJob.java index 9642cbc..8ebb34b 100644 --- a/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/job/DeadlineOrderJob.java +++ b/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/job/DeadlineOrderJob.java @@ -5,7 +5,13 @@ import com.agileboot.domain.cabinet.cell.db.CabinetCellEntity; import com.agileboot.domain.cabinet.cell.db.CabinetCellService; import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetEntity; import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetService; +import com.agileboot.domain.qywx.accessToken.AccessTokenApplicationService; +import com.agileboot.domain.qywx.accessToken.db.QyAccessTokenEntity; +import com.agileboot.domain.qywx.api.QywxApiUtil; +import com.agileboot.domain.qywx.api.response.NewsArticle; +import com.agileboot.domain.qywx.authCorpInfo.AuthCorpInfoApplicationService; import com.agileboot.domain.qywx.authCorpInfo.db.QyAuthCorpInfoEntity; +import com.agileboot.domain.qywx.user.db.QyUserService; import com.agileboot.domain.shop.order.db.ShopOrderEntity; import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity; import com.agileboot.domain.shop.order.db.ShopOrderGoodsService; @@ -20,6 +26,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -32,6 +39,9 @@ public class DeadlineOrderJob { private final CabinetCellService cabinetCellService; private final SmartCabinetService smartCabinetService; private final PaymentOperationLogApplicationService paymentOperationLogApplicationService; + private final AuthCorpInfoApplicationService authCorpInfoApplicationService; + private final AccessTokenApplicationService accessTokenApplicationService; + private final QyUserService qyUserService; /** * 定时任务:处理超过归还期限的订单商品 @@ -123,26 +133,29 @@ public class DeadlineOrderJob { // 1. 更新订单商品状态为“已逾期” orderGoods.setStatus(ShopOrderGoodsEntity.STATUS_OVERDUE); // STATUS_OVERDUE = 7 -// shopOrderGoodsService.updateById(orderGoods); // 更新数据库 + shopOrderGoodsService.updateById(orderGoods); // 更新数据库 // 2. 将商品从智能柜格口下架 cabinetCell.setGoodsId(null); // 清除关联商品ID cabinetCell.setUsageStatus(1); // 使用状态改为1-空闲 -// cabinetCellService.updateById(cabinetCell); // 更新数据库 + cabinetCellService.updateById(cabinetCell); // 更新数据库 log.info("成功处理逾期商品:订单商品ID[{}]状态更新为已逾期,并从格口ID[{}]下架。", orderGoods.getOrderGoodsId(), cabinetCell.getCellId()); + // 创建操作日志 + createPaymentOperationLog(order, orderGoods, returnDeadlineDays, deadlineDate); + + // 发送审核消息 try { - AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand(); - paymentOperationLogCommand.setOperationType("DeadlineOrder"); - paymentOperationLogCommand.setStatus(1); - paymentOperationLogCommand.setRemark( - String.format("逾期订单商品:订单号[%s], 商品ID[%s], 名称[%s]。创建时间[%s], 归还期限[%s天], 截止日期[%s].", - order.getOrderId(), orderGoods.getOrderGoodsId(), orderGoods.getGoodsName(), DateUtil.formatDateTime(orderCreateTime), returnDeadlineDays, DateUtil.formatDateTime(deadlineDate))); - paymentOperationLogCommand.initBaseEntity(); - paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand); + String appid = "QWTONG_YS_WXSHOP"; + List authCorpInfoList = authCorpInfoApplicationService.getByAppid(appid); + QyAuthCorpInfoEntity authCorpInfo = authCorpInfoList.stream() + .filter(a -> order.getCorpid().equals(a.getCorpid())) + .findFirst().orElse(null); + QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, authCorpInfo.getCorpid()); + sendReviewNotification(order, orderGoods, authCorpInfo, accessToken, returnDeadlineDays, deadlineDate); } catch (Exception e) { - log.error("处理逾期订单商品[{}]时创建退款操作日志失败.", orderGoods.getOrderGoodsId(), e); + log.error("发送逾期未归还通知失败", e); } } } @@ -152,4 +165,47 @@ public class DeadlineOrderJob { } log.info("逾期订单处理及商品下架任务执行完毕."); } + + /** + * 创建逾期订单操作日志 + */ + private void createPaymentOperationLog(ShopOrderEntity order, ShopOrderGoodsEntity orderGoods, int returnDeadlineDays, Date deadlineDate) { + try { + AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand(); + paymentOperationLogCommand.setOperationType("DeadlineOrder"); + paymentOperationLogCommand.setStatus(1); + paymentOperationLogCommand.setRemark( + String.format("逾期订单商品:订单号[%s], 商品ID[%s], 名称[%s]。创建时间[%s], 归还期限[%s天], 截止日期[%s].", + order.getOrderId(), orderGoods.getOrderGoodsId(), orderGoods.getGoodsName(), DateUtil.formatDateTime(order.getCreateTime()), returnDeadlineDays, DateUtil.formatDateTime(deadlineDate))); + paymentOperationLogCommand.initBaseEntity(); + paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand); + } catch (Exception e) { + log.error("处理逾期订单商品[{}]时创建退款操作日志失败.", orderGoods.getOrderGoodsId(), e); + } + } + + /** + * 发送逾期商品审核通知 + */ + private void sendReviewNotification(ShopOrderEntity order, ShopOrderGoodsEntity orderGoods, QyAuthCorpInfoEntity authCorpInfo, QyAccessTokenEntity accessToken, int returnDeadlineDays, Date deadlineDate) { + try { + List adminUserIds = qyUserService.selectAdminUserIds(order.getCorpid()); + String toUser = String.join("|", adminUserIds); + String toparty = ""; + String totag = ""; + List articles = new ArrayList<>(); + NewsArticle article = new NewsArticle(); + article.setTitle("逾期商品自动下架通知"); + article.setDescription(String.format("订单号: %s, 商品名称: %s, 创建时间: %s, 归还期限: %s天, 截止日期: %s", + order.getOrderId(), orderGoods.getGoodsName(), DateUtil.formatDateTime(order.getCreateTime()), returnDeadlineDays, DateUtil.formatDateTime(deadlineDate))); + article.setPicurl(orderGoods.getCoverImg()); + article.setUrl("http://wxshop.ab98.cn/shop-api/api/shop/qy/wechatAuth"); + articles.add(article); + + QywxApiUtil.sendNewsMessage(accessToken.getAccessToken(), Integer.valueOf(authCorpInfo.getAgentid()), + toUser, toparty, totag, articles); + } catch (Exception e) { + log.error("发送逾期未归还通知失败", e); + } + } }