feat(DeadlineOrderJob): 添加逾期订单处理通知功能
- 在QywxScheduleJob中添加日志记录微信用户信息 - 重构DeadlineOrderJob,添加企业微信通知功能 - 将创建操作日志和发送通知逻辑提取为独立方法 - 修复订单创建时间引用错误问题
This commit is contained in:
parent
9f04fe0ce3
commit
9e9b3a5cb5
|
@ -459,6 +459,8 @@ public class QywxScheduleJob {
|
||||||
List<UserListResponse.UserInfo> toAdd = wxUsers.stream()
|
List<UserListResponse.UserInfo> toAdd = wxUsers.stream()
|
||||||
.filter(wxUser -> !existingUserIds.contains(wxUser.getUserid()))
|
.filter(wxUser -> !existingUserIds.contains(wxUser.getUserid()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
log.info("wxUsers: {}", JSONUtil.toJsonStr(wxUsers));
|
||||||
|
log.info("existingUserIds: {}", JSONUtil.toJsonStr(existingUserIds));
|
||||||
log.info("syncUserInfo toAdd: {}", JSONUtil.toJsonStr(toAdd));
|
log.info("syncUserInfo toAdd: {}", JSONUtil.toJsonStr(toAdd));
|
||||||
|
|
||||||
// 识别需要删除的用户
|
// 识别需要删除的用户
|
||||||
|
|
|
@ -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.cell.db.CabinetCellService;
|
||||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetEntity;
|
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetEntity;
|
||||||
import com.agileboot.domain.cabinet.smartCabinet.db.SmartCabinetService;
|
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.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.ShopOrderEntity;
|
||||||
import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity;
|
import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity;
|
||||||
import com.agileboot.domain.shop.order.db.ShopOrderGoodsService;
|
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.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,6 +39,9 @@ public class DeadlineOrderJob {
|
||||||
private final CabinetCellService cabinetCellService;
|
private final CabinetCellService cabinetCellService;
|
||||||
private final SmartCabinetService smartCabinetService;
|
private final SmartCabinetService smartCabinetService;
|
||||||
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
||||||
|
private final AuthCorpInfoApplicationService authCorpInfoApplicationService;
|
||||||
|
private final AccessTokenApplicationService accessTokenApplicationService;
|
||||||
|
private final QyUserService qyUserService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务:处理超过归还期限的订单商品
|
* 定时任务:处理超过归还期限的订单商品
|
||||||
|
@ -123,26 +133,29 @@ public class DeadlineOrderJob {
|
||||||
|
|
||||||
// 1. 更新订单商品状态为“已逾期”
|
// 1. 更新订单商品状态为“已逾期”
|
||||||
orderGoods.setStatus(ShopOrderGoodsEntity.STATUS_OVERDUE); // STATUS_OVERDUE = 7
|
orderGoods.setStatus(ShopOrderGoodsEntity.STATUS_OVERDUE); // STATUS_OVERDUE = 7
|
||||||
// shopOrderGoodsService.updateById(orderGoods); // 更新数据库
|
shopOrderGoodsService.updateById(orderGoods); // 更新数据库
|
||||||
|
|
||||||
// 2. 将商品从智能柜格口下架
|
// 2. 将商品从智能柜格口下架
|
||||||
cabinetCell.setGoodsId(null); // 清除关联商品ID
|
cabinetCell.setGoodsId(null); // 清除关联商品ID
|
||||||
cabinetCell.setUsageStatus(1); // 使用状态改为1-空闲
|
cabinetCell.setUsageStatus(1); // 使用状态改为1-空闲
|
||||||
// cabinetCellService.updateById(cabinetCell); // 更新数据库
|
cabinetCellService.updateById(cabinetCell); // 更新数据库
|
||||||
|
|
||||||
log.info("成功处理逾期商品:订单商品ID[{}]状态更新为已逾期,并从格口ID[{}]下架。", orderGoods.getOrderGoodsId(), cabinetCell.getCellId());
|
log.info("成功处理逾期商品:订单商品ID[{}]状态更新为已逾期,并从格口ID[{}]下架。", orderGoods.getOrderGoodsId(), cabinetCell.getCellId());
|
||||||
|
|
||||||
|
// 创建操作日志
|
||||||
|
createPaymentOperationLog(order, orderGoods, returnDeadlineDays, deadlineDate);
|
||||||
|
|
||||||
|
// 发送审核消息
|
||||||
try {
|
try {
|
||||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
String appid = "QWTONG_YS_WXSHOP";
|
||||||
paymentOperationLogCommand.setOperationType("DeadlineOrder");
|
List<QyAuthCorpInfoEntity> authCorpInfoList = authCorpInfoApplicationService.getByAppid(appid);
|
||||||
paymentOperationLogCommand.setStatus(1);
|
QyAuthCorpInfoEntity authCorpInfo = authCorpInfoList.stream()
|
||||||
paymentOperationLogCommand.setRemark(
|
.filter(a -> order.getCorpid().equals(a.getCorpid()))
|
||||||
String.format("逾期订单商品:订单号[%s], 商品ID[%s], 名称[%s]。创建时间[%s], 归还期限[%s天], 截止日期[%s].",
|
.findFirst().orElse(null);
|
||||||
order.getOrderId(), orderGoods.getOrderGoodsId(), orderGoods.getGoodsName(), DateUtil.formatDateTime(orderCreateTime), returnDeadlineDays, DateUtil.formatDateTime(deadlineDate)));
|
QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, authCorpInfo.getCorpid());
|
||||||
paymentOperationLogCommand.initBaseEntity();
|
sendReviewNotification(order, orderGoods, authCorpInfo, accessToken, returnDeadlineDays, deadlineDate);
|
||||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理逾期订单商品[{}]时创建退款操作日志失败.", orderGoods.getOrderGoodsId(), e);
|
log.error("发送逾期未归还通知失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,4 +165,47 @@ public class DeadlineOrderJob {
|
||||||
}
|
}
|
||||||
log.info("逾期订单处理及商品下架任务执行完毕.");
|
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<String> adminUserIds = qyUserService.selectAdminUserIds(order.getCorpid());
|
||||||
|
String toUser = String.join("|", adminUserIds);
|
||||||
|
String toparty = "";
|
||||||
|
String totag = "";
|
||||||
|
List<NewsArticle> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue